Class BundleContextImpl.ServiceObjectsImpl<S>

java.lang.Object
org.apache.felix.framework.BundleContextImpl.ServiceObjectsImpl<S>
All Implemented Interfaces:
ServiceObjects<S>
Enclosing class:
BundleContextImpl

class BundleContextImpl.ServiceObjectsImpl<S> extends Object implements ServiceObjects<S>
  • Field Details

  • Constructor Details

  • Method Details

    • getService

      public S getService()
      Description copied from interface: ServiceObjects
      Returns a service object for the associated service.

      This ServiceObjects object can be used to obtain multiple service objects for the associated service if the service has prototype scope.

      If the associated service has singleton or bundle scope, this method behaves the same as calling the BundleContext.getService(ServiceReference) method for the associated service. That is, only one, use-counted service object is available from this ServiceObjects object.

      This method will always return null when the associated service has been unregistered.

      For a prototype scope service, the following steps are required to obtain a service object:

      1. If the associated service has been unregistered, null is returned.
      2. The PrototypeServiceFactory.getService(Bundle, ServiceRegistration) method is called to supply a customized service object for the caller.
      3. If the service object returned by the PrototypeServiceFactory object is null, not an instanceof all the classes named when the service was registered or the PrototypeServiceFactory object throws an exception, null is returned and a Framework event of type FrameworkEvent.ERROR containing a ServiceException describing the error is fired.
      4. The customized service object is returned.
      Specified by:
      getService in interface ServiceObjects<S>
      Returns:
      A service object for the associated service or null if the service is not registered, the customized service object returned by a ServiceFactory does not implement the classes under which it was registered or the ServiceFactory threw an exception.
      See Also:
    • ungetService

      public void ungetService(S srvObj)
      Description copied from interface: ServiceObjects
      Releases a service object for the associated service.

      This ServiceObjects object can be used to obtain multiple service objects for the associated service if the service has prototype scope. If the associated service has singleton or bundle scope, this method behaves the same as calling the BundleContext.ungetService(ServiceReference) method for the associated service. That is, only one, use-counted service object is available from this ServiceObjects object.

      For a prototype scope service, the following steps are required to release a service object:

      1. If the associated service has been unregistered, this method returns without doing anything.
      2. The PrototypeServiceFactory.ungetService(Bundle, ServiceRegistration, Object) method is called to release the specified service object.

      The specified service object must no longer be used and all references to it should be destroyed after calling this method.

      Specified by:
      ungetService in interface ServiceObjects<S>
      Parameters:
      srvObj - A service object previously provided by this ServiceObjects object.
      See Also:
    • getServiceReference

      public ServiceReference<S> getServiceReference()
      Description copied from interface: ServiceObjects
      Returns the ServiceReference for the service associated with this ServiceObjects object.
      Specified by:
      getServiceReference in interface ServiceObjects<S>
      Returns:
      The ServiceReference for the service associated with this ServiceObjects object.