Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 2 | * Copyright (c) OSGi Alliance (2000, 2009). All Rights Reserved. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.osgi.framework; |
| 18 | |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 19 | import java.util.Dictionary; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 20 | import java.util.EventObject; |
| 21 | |
| 22 | /** |
| 23 | * An event from the Framework describing a service lifecycle change. |
| 24 | * <p> |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 25 | * <code>ServiceEvent</code> objects are delivered to |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 26 | * <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. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 28 | * the event type for future extendability. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 29 | * |
| 30 | * <p> |
| 31 | * OSGi Alliance reserves the right to extend the set of types. |
| 32 | * |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 33 | * @Immutable |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 34 | * @see ServiceListener |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 35 | * @see AllServiceListener |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 36 | * @version $Revision: 6542 $ |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | public class ServiceEvent extends EventObject { |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 40 | static final long serialVersionUID = 8792901483909409299L; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Reference to the service that had a change occur in its lifecycle. |
| 43 | */ |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 44 | private final ServiceReference reference; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Type of service lifecycle change. |
| 48 | */ |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 49 | private final int type; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 50 | |
| 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. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 57 | * @see BundleContext#registerService(String[],Object,Dictionary) |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 58 | */ |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 59 | public final static int REGISTERED = 0x00000001; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 60 | |
| 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. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 67 | * @see ServiceRegistration#setProperties |
| 68 | */ |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 69 | public final static int MODIFIED = 0x00000002; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * This service is in the process of being unregistered. |
| 73 | * <p> |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 74 | * This event is synchronously delivered <strong>before</strong> the service |
| 75 | * has completed unregistering. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 76 | * |
| 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. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 84 | * @see ServiceRegistration#unregister |
| 85 | * @see BundleContext#ungetService |
| 86 | */ |
Richard S. Hall | 53e70d3 | 2008-08-01 19:31:32 +0000 | [diff] [blame] | 87 | public final static int UNREGISTERING = 0x00000004; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 88 | |
| 89 | /** |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 90 | * 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. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 105 | * 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. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 109 | * that had a lifecycle change. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 110 | */ |
| 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. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 132 | * <li>{@link #REGISTERED} </li> |
| 133 | * <li>{@link #MODIFIED} </li> |
| 134 | * <li>{@link #MODIFIED_ENDMATCH} </li> |
| 135 | * <li>{@link #UNREGISTERING} </li> |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 136 | * </ul> |
| 137 | * |
| 138 | * @return Type of service lifecycle change. |
| 139 | */ |
| 140 | |
| 141 | public int getType() { |
| 142 | return type; |
| 143 | } |
| 144 | } |