org.eclipse.osgi.internal.serviceregistry
Class ServiceRegistrationImpl

java.lang.Object
  extended by org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl
All Implemented Interfaces:
java.lang.Comparable, ServiceRegistration

public class ServiceRegistrationImpl
extends java.lang.Object
implements ServiceRegistration, java.lang.Comparable

A registered service. The framework returns a ServiceRegistration object when a BundleContext.registerService method is successful. This object is for the private use of the registering bundle and should not be shared with other bundles.

The ServiceRegistration object may be used to update the properties for the service or to unregister the service.

If the ServiceRegistration is garbage collected the framework may remove the service. This implies that if a bundle wants to keep its service registered, it should keep the ServiceRegistration object referenced.


Method Summary
 int compareTo(java.lang.Object object)
          Compares this ServiceRegistrationImpl with the specified ServiceRegistrationImpl for order.
 org.eclipse.osgi.internal.serviceregistry.ServiceProperties getProperties()
          Return the properties object.
 ServiceReference getReference()
          Returns a ServiceReferenceImpl object for this registration.
 void setProperties(java.util.Dictionary props)
          Update the properties associated with this service.
 java.lang.String toString()
          Return a String representation of this object.
 void unregister()
          Unregister the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

setProperties

public void setProperties(java.util.Dictionary props)
Update the properties associated with this service.

The key "objectClass" cannot be modified by this method. It's value is set when the service is registered.

The following steps are followed to modify a service's properties:

  1. The service's properties are replaced with the provided properties.
  2. A ServiceEvent of type ServiceEvent.MODIFIED is synchronously sent.

Specified by:
setProperties in interface ServiceRegistration
Parameters:
props - The properties for this service. Changes should not be made to this object after calling this method. To update the service's properties this method should be called again.
Throws:
java.lang.IllegalStateException - If this ServiceRegistration has already been unregistered.
java.lang.IllegalArgumentException - If the properties parameter contains case variants of the same key name.

unregister

public void unregister()
Unregister the service. Remove a service registration from the framework's service registry. All ServiceReferenceImpl objects for this registration can no longer be used to interact with the service.

The following steps are followed to unregister a service:

  1. The service is removed from the framework's service registry so that it may no longer be used. ServiceReferenceImpls for the service may no longer be used to get a service object for the service.
  2. A ServiceEvent of type ServiceEvent.UNREGISTERING is synchronously sent so that bundles using this service may release their use of the service.
  3. For each bundle whose use count for this service is greater than zero:
    1. The bundle's use count for this service is set to zero.
    2. If the service was registered with a ServiceFactory, the ServiceFactory.ungetService method is called to release the service object for the bundle.

Specified by:
unregister in interface ServiceRegistration
Throws:
java.lang.IllegalStateException - If this ServiceRegistration has already been unregistered.
See Also:
BundleContextImpl.ungetService(org.osgi.framework.ServiceReference)

getReference

public ServiceReference getReference()
Returns a ServiceReferenceImpl object for this registration. The ServiceReferenceImpl object may be shared with other bundles.

Specified by:
getReference in interface ServiceRegistration
Returns:
A ServiceReferenceImpl object.
Throws:
java.lang.IllegalStateException - If this ServiceRegistration has already been unregistered.

getProperties

public org.eclipse.osgi.internal.serviceregistry.ServiceProperties getProperties()
Return the properties object. This is for framework internal use only.

Returns:
The service registration's properties.

toString

public java.lang.String toString()
Return a String representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
String representation of this object.

compareTo

public int compareTo(java.lang.Object object)
Compares this ServiceRegistrationImpl with the specified ServiceRegistrationImpl for order.

This does a reverse comparison so that the highest item is sorted to the left. We keep ServiceRegistationImpls in sorted lists such that the highest ranked service is at element 0 for quick retrieval.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - The ServiceRegistrationImpl to be compared.
Returns:
Returns a negative integer, zero, or a positive integer if this ServiceRegistrationImpl is greater than, equal to, or less than the specified ServiceRegistrationImpl.


Copyright © 2007-2012 FuseSource, Corp.. All Rights Reserved.