org.eclipse.osgi.framework.internal.core
Class ServiceRegistrationImpl

java.lang.Object
  extended by org.eclipse.osgi.framework.internal.core.ServiceRegistrationImpl
All Implemented Interfaces:
ServiceRegistration

public class ServiceRegistrationImpl
extends java.lang.Object
implements ServiceRegistration

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.


Field Summary
protected  AbstractBundle bundle
          bundle which registered this service.
protected  java.lang.String[] clazzes
          service classes for this registration.
protected  BundleContextImpl context
          context which registered this service.
protected  java.util.ArrayList contextsUsing
          list of contexts using the service.
protected  Framework framework
          Internal framework object.
protected  org.eclipse.osgi.framework.internal.core.ServiceRegistrationImpl.Properties properties
          properties for this registration.
protected  ServiceReferenceImpl reference
          Reference to this registration.
static int REGISTERED
           
protected  java.lang.Object registrationLock
           
protected  java.lang.Object service
          service object for this registration.
protected  long serviceid
          service id.
protected  int serviceranking
          service ranking.
protected  int state
          The registration state
static int UNREGISTERED
           
static int UNREGISTERING
           
 
Constructor Summary
protected ServiceRegistrationImpl(BundleContextImpl context, java.lang.String[] clazzes, java.lang.Object service, java.util.Dictionary properties)
          Construct a ServiceRegistration and register the service in the framework's service registry.
 
Method Summary
protected  org.eclipse.osgi.framework.internal.core.ServiceRegistrationImpl.Properties createProperties(java.util.Dictionary props)
          Construct a properties object from the dictionary for this ServiceRegistration.
protected  AbstractBundle getBundle()
          Return the bundle which registered the service.
protected  java.lang.Object getProperty(java.lang.String key)
          Get the value of a service's property.
protected  java.lang.String[] getPropertyKeys()
          Get the list of key names for the service's properties.
 ServiceReference getReference()
          Returns a ServiceReferenceImpl object for this registration.
protected  java.lang.Object getService(BundleContextImpl user)
          Get a service object for the using BundleContext.
protected  AbstractBundle[] getUsingBundles()
          Return the list of bundle which are using this service.
protected  void releaseService(BundleContextImpl user)
          Release the service for the using BundleContext.
 void setProperties(java.util.Dictionary props)
          Update the properties associated with this service.
 java.lang.String toString()
          Return a String representation of this object.
protected  boolean ungetService(BundleContextImpl user)
          Unget a service for the using BundleContext.
 void unregister()
          Unregister the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

reference

protected ServiceReferenceImpl reference
Reference to this registration.


framework

protected Framework framework
Internal framework object.


context

protected BundleContextImpl context
context which registered this service.


bundle

protected AbstractBundle bundle
bundle which registered this service.


contextsUsing

protected java.util.ArrayList contextsUsing
list of contexts using the service. Access to this should be protected by the registrationLock


clazzes

protected java.lang.String[] clazzes
service classes for this registration.


service

protected java.lang.Object service
service object for this registration.


properties

protected org.eclipse.osgi.framework.internal.core.ServiceRegistrationImpl.Properties properties
properties for this registration.


serviceid

protected long serviceid
service id.


serviceranking

protected int serviceranking
service ranking.


registrationLock

protected java.lang.Object registrationLock

state

protected int state
The registration state


REGISTERED

public static final int REGISTERED
See Also:
Constant Field Values

UNREGISTERING

public static final int UNREGISTERING
See Also:
Constant Field Values

UNREGISTERED

public static final int UNREGISTERED
See Also:
Constant Field Values
Constructor Detail

ServiceRegistrationImpl

protected ServiceRegistrationImpl(BundleContextImpl context,
                                  java.lang.String[] clazzes,
                                  java.lang.Object service,
                                  java.util.Dictionary properties)
Construct a ServiceRegistration and register the service in the framework's service registry.

Method Detail

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.

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.

createProperties

protected org.eclipse.osgi.framework.internal.core.ServiceRegistrationImpl.Properties createProperties(java.util.Dictionary props)
Construct a properties object from the dictionary for this ServiceRegistration.

Parameters:
props - The properties for this service.
Returns:
A Properties object for this ServiceRegistration.

getProperty

protected java.lang.Object getProperty(java.lang.String key)
Get the value of a service's property.

This method will continue to return property values after the service has been unregistered. This is so that references to unregistered service can be interrogated. (For example: ServiceReference objects stored in the log.)

Parameters:
key - Name of the property.
Returns:
Value of the property or null if there is no property by that name.

getPropertyKeys

protected java.lang.String[] getPropertyKeys()
Get the list of key names for the service's properties.

This method will continue to return the keys after the service has been unregistered. This is so that references to unregistered service can be interrogated. (For example: ServiceReference objects stored in the log.)

Returns:
The list of property key names.

getBundle

protected AbstractBundle getBundle()
Return the bundle which registered the service.

This method will always return null when the service has been unregistered. This can be used to determine if the service has been unregistered.

Returns:
The bundle which registered the service.

getService

protected java.lang.Object getService(BundleContextImpl user)
Get a service object for the using BundleContext.

Parameters:
user - BundleContext using service.
Returns:
Service object

ungetService

protected boolean ungetService(BundleContextImpl user)
Unget a service for the using BundleContext.

Parameters:
user - BundleContext using service.
Returns:
false if the context bundle's use count for the service is zero or if the service has been unregistered, otherwise true.

releaseService

protected void releaseService(BundleContextImpl user)
Release the service for the using BundleContext.

Parameters:
user - BundleContext using service.

getUsingBundles

protected AbstractBundle[] getUsingBundles()
Return the list of bundle which are using this service.

Returns:
Array of Bundles using this service.

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.