blob: 6f76863d1813d82509033131bac8ec982dc47354 [file] [log] [blame]
Richard S. Hallc88fca32006-10-18 22:01:22 +00001/*
Richard S. Hall53e70d32008-08-01 19:31:32 +00002 * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceEvent.java,v 1.15 2007/02/20 00:14:12 hargrave Exp $
Richard S. Hallc88fca32006-10-18 22:01:22 +00003 *
Richard S. Hall53e70d32008-08-01 19:31:32 +00004 * Copyright (c) OSGi Alliance (2000, 2007). All Rights Reserved.
Richard S. Hallc88fca32006-10-18 22:01:22 +00005 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.osgi.framework;
20
21import java.util.EventObject;
22
23/**
24 * An event from the Framework describing a service lifecycle change.
25 * <p>
Richard S. Hall53e70d32008-08-01 19:31:32 +000026 * <code>ServiceEvent</code> objects are delivered to
27 * <code>ServiceListener</code>s and <code>AllServiceListener</code>s when
28 * a change occurs in this service's lifecycle. A type code is used to identify
29 * the event type for future extendability.
Richard S. Hallc88fca32006-10-18 22:01:22 +000030 *
31 * <p>
32 * OSGi Alliance reserves the right to extend the set of types.
33 *
Richard S. Hall53e70d32008-08-01 19:31:32 +000034 * @Immutable
Richard S. Hallc88fca32006-10-18 22:01:22 +000035 * @see ServiceListener
Richard S. Hall53e70d32008-08-01 19:31:32 +000036 * @see AllServiceListener
37 * @version $Revision: 1.15 $
Richard S. Hallc88fca32006-10-18 22:01:22 +000038 */
39
40public class ServiceEvent extends EventObject {
Richard S. Hall53e70d32008-08-01 19:31:32 +000041 static final long serialVersionUID = 8792901483909409299L;
Richard S. Hallc88fca32006-10-18 22:01:22 +000042 /**
43 * Reference to the service that had a change occur in its lifecycle.
44 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000045 private final ServiceReference reference;
Richard S. Hallc88fca32006-10-18 22:01:22 +000046
47 /**
48 * Type of service lifecycle change.
49 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000050 private final int type;
Richard S. Hallc88fca32006-10-18 22:01:22 +000051
52 /**
53 * This service has been registered.
54 * <p>
55 * This event is synchronously delivered <strong>after</strong> the service
56 * has been registered with the Framework.
57 *
58 * <p>
59 * The value of <code>REGISTERED</code> is 0x00000001.
60 *
61 * @see BundleContext#registerService(String[],Object,java.util.Dictionary)
62 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000063 public final static int REGISTERED = 0x00000001;
Richard S. Hallc88fca32006-10-18 22:01:22 +000064
65 /**
66 * The properties of a registered service have been modified.
67 * <p>
68 * This event is synchronously delivered <strong>after</strong> the service
69 * properties have been modified.
70 *
71 * <p>
72 * The value of <code>MODIFIED</code> is 0x00000002.
73 *
74 * @see ServiceRegistration#setProperties
75 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000076 public final static int MODIFIED = 0x00000002;
Richard S. Hallc88fca32006-10-18 22:01:22 +000077
78 /**
79 * This service is in the process of being unregistered.
80 * <p>
81 * This event is synchronously delivered <strong>before</strong> the
82 * service has completed unregistering.
83 *
84 * <p>
85 * If a bundle is using a service that is <code>UNREGISTERING</code>, the
86 * bundle should release its use of the service when it receives this event.
87 * If the bundle does not release its use of the service when it receives
88 * this event, the Framework will automatically release the bundle's use of
89 * the service while completing the service unregistration operation.
90 *
91 * <p>
92 * The value of UNREGISTERING is 0x00000004.
93 *
94 * @see ServiceRegistration#unregister
95 * @see BundleContext#ungetService
96 */
Richard S. Hall53e70d32008-08-01 19:31:32 +000097 public final static int UNREGISTERING = 0x00000004;
Richard S. Hallc88fca32006-10-18 22:01:22 +000098
99 /**
100 * Creates a new service event object.
101 *
102 * @param type The event type.
103 * @param reference A <code>ServiceReference</code> object to the service
104 * that had a lifecycle change.
105 */
106 public ServiceEvent(int type, ServiceReference reference) {
107 super(reference);
108 this.reference = reference;
109 this.type = type;
110 }
111
112 /**
113 * Returns a reference to the service that had a change occur in its
114 * lifecycle.
115 * <p>
116 * This reference is the source of the event.
117 *
118 * @return Reference to the service that had a lifecycle change.
119 */
120 public ServiceReference getServiceReference() {
121 return reference;
122 }
123
124 /**
125 * Returns the type of event. The event type values are:
126 * <ul>
127 * <li>{@link #REGISTERED}
128 * <li>{@link #MODIFIED}
129 * <li>{@link #UNREGISTERING}
130 * </ul>
131 *
132 * @return Type of service lifecycle change.
133 */
134
135 public int getType() {
136 return type;
137 }
138}