blob: b7c9928dcc9dd52d42d19d9fc75f6237c3fb5f03 [file] [log] [blame]
Richard S. Hallc88fca32006-10-18 22:01:22 +00001/*
Richard S. Hallf28d6762009-06-08 19:31:06 +00002 * Copyright (c) OSGi Alliance (2000, 2009). All Rights Reserved.
Richard S. Hallc88fca32006-10-18 22:01:22 +00003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.osgi.framework;
18
Richard S. Hallf28d6762009-06-08 19:31:06 +000019import java.util.Dictionary;
Richard S. Hallc88fca32006-10-18 22:01:22 +000020import java.util.EventObject;
21
22/**
23 * An event from the Framework describing a service lifecycle change.
24 * <p>
Richard S. Hall53e70d32008-08-01 19:31:32 +000025 * <code>ServiceEvent</code> objects are delivered to
Richard S. Hallf28d6762009-06-08 19:31:06 +000026 * <code>ServiceListener</code>s and <code>AllServiceListener</code>s when a
27 * change occurs in this service's lifecycle. A type code is used to identify
Richard S. Hall53e70d32008-08-01 19:31:32 +000028 * the event type for future extendability.
Richard S. Hallc88fca32006-10-18 22:01:22 +000029 *
30 * <p>
31 * OSGi Alliance reserves the right to extend the set of types.
32 *
Richard S. Hall53e70d32008-08-01 19:31:32 +000033 * @Immutable
Richard S. Hallc88fca32006-10-18 22:01:22 +000034 * @see ServiceListener
Richard S. Hall53e70d32008-08-01 19:31:32 +000035 * @see AllServiceListener
Richard S. Hallf28d6762009-06-08 19:31:06 +000036 * @version $Revision: 6542 $
Richard S. Hallc88fca32006-10-18 22:01:22 +000037 */
38
39public class ServiceEvent extends EventObject {
Richard S. Hall53e70d32008-08-01 19:31:32 +000040 static final long serialVersionUID = 8792901483909409299L;
Richard S. Hallc88fca32006-10-18 22:01:22 +000041 /**
42 * Reference to the service that had a change occur in its lifecycle.
43 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000044 private final ServiceReference reference;
Richard S. Hallc88fca32006-10-18 22:01:22 +000045
46 /**
47 * Type of service lifecycle change.
48 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000049 private final int type;
Richard S. Hallc88fca32006-10-18 22:01:22 +000050
51 /**
52 * This service has been registered.
53 * <p>
54 * This event is synchronously delivered <strong>after</strong> the service
55 * has been registered with the Framework.
56 *
Richard S. Hallf28d6762009-06-08 19:31:06 +000057 * @see BundleContext#registerService(String[],Object,Dictionary)
Richard S. Hallc88fca32006-10-18 22:01:22 +000058 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000059 public final static int REGISTERED = 0x00000001;
Richard S. Hallc88fca32006-10-18 22:01:22 +000060
61 /**
62 * The properties of a registered service have been modified.
63 * <p>
64 * This event is synchronously delivered <strong>after</strong> the service
65 * properties have been modified.
66 *
Richard S. Hallc88fca32006-10-18 22:01:22 +000067 * @see ServiceRegistration#setProperties
68 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000069 public final static int MODIFIED = 0x00000002;
Richard S. Hallc88fca32006-10-18 22:01:22 +000070
71 /**
72 * This service is in the process of being unregistered.
73 * <p>
Richard S. Hallf28d6762009-06-08 19:31:06 +000074 * This event is synchronously delivered <strong>before</strong> the service
75 * has completed unregistering.
Richard S. Hallc88fca32006-10-18 22:01:22 +000076 *
77 * <p>
78 * If a bundle is using a service that is <code>UNREGISTERING</code>, the
79 * bundle should release its use of the service when it receives this event.
80 * If the bundle does not release its use of the service when it receives
81 * this event, the Framework will automatically release the bundle's use of
82 * the service while completing the service unregistration operation.
83 *
Richard S. Hallc88fca32006-10-18 22:01:22 +000084 * @see ServiceRegistration#unregister
85 * @see BundleContext#ungetService
86 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000087 public final static int UNREGISTERING = 0x00000004;
Richard S. Hallc88fca32006-10-18 22:01:22 +000088
89 /**
Richard S. Hallf28d6762009-06-08 19:31:06 +000090 * The properties of a registered service have been modified and the new
91 * properties no longer match the listener's filter.
92 * <p>
93 * This event is synchronously delivered <strong>after</strong> the service
94 * properties have been modified. This event is only delivered to listeners
95 * which were added with a non-<code>null</code> filter where the filter
96 * matched the service properties prior to the modification but the filter
97 * does not match the modified service properties.
98 *
99 * @see ServiceRegistration#setProperties
100 * @since 1.5
101 */
102 public final static int MODIFIED_ENDMATCH = 0x00000008;
103
104 /**
Richard S. Hallc88fca32006-10-18 22:01:22 +0000105 * Creates a new service event object.
106 *
107 * @param type The event type.
108 * @param reference A <code>ServiceReference</code> object to the service
Richard S. Hallf28d6762009-06-08 19:31:06 +0000109 * that had a lifecycle change.
Richard S. Hallc88fca32006-10-18 22:01:22 +0000110 */
111 public ServiceEvent(int type, ServiceReference reference) {
112 super(reference);
113 this.reference = reference;
114 this.type = type;
115 }
116
117 /**
118 * Returns a reference to the service that had a change occur in its
119 * lifecycle.
120 * <p>
121 * This reference is the source of the event.
122 *
123 * @return Reference to the service that had a lifecycle change.
124 */
125 public ServiceReference getServiceReference() {
126 return reference;
127 }
128
129 /**
130 * Returns the type of event. The event type values are:
131 * <ul>
Richard S. Hallf28d6762009-06-08 19:31:06 +0000132 * <li>{@link #REGISTERED} </li>
133 * <li>{@link #MODIFIED} </li>
134 * <li>{@link #MODIFIED_ENDMATCH} </li>
135 * <li>{@link #UNREGISTERING} </li>
Richard S. Hallc88fca32006-10-18 22:01:22 +0000136 * </ul>
137 *
138 * @return Type of service lifecycle change.
139 */
140
141 public int getType() {
142 return type;
143 }
144}