Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 2 | * $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. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 3 | * |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 4 | * Copyright (c) OSGi Alliance (2000, 2007). All Rights Reserved. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 5 | * |
| 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 | |
| 19 | package org.osgi.framework; |
| 20 | |
| 21 | import java.util.EventObject; |
| 22 | |
| 23 | /** |
| 24 | * An event from the Framework describing a service lifecycle change. |
| 25 | * <p> |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 26 | * <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. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 30 | * |
| 31 | * <p> |
| 32 | * OSGi Alliance reserves the right to extend the set of types. |
| 33 | * |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 34 | * @Immutable |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 35 | * @see ServiceListener |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 36 | * @see AllServiceListener |
| 37 | * @version $Revision: 1.15 $ |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | public class ServiceEvent extends EventObject { |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 41 | static final long serialVersionUID = 8792901483909409299L; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 42 | /** |
| 43 | * Reference to the service that had a change occur in its lifecycle. |
| 44 | */ |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 45 | private final ServiceReference reference; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Type of service lifecycle change. |
| 49 | */ |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 50 | private final int type; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 51 | |
| 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. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 63 | public final static int REGISTERED = 0x00000001; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 64 | |
| 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. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 76 | public final static int MODIFIED = 0x00000002; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 77 | |
| 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. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame^] | 97 | public final static int UNREGISTERING = 0x00000004; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 98 | |
| 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 | } |