org.apache.felix.prefs.impl
Class PreferencesManager

java.lang.Object
  extended by org.apache.felix.prefs.impl.PreferencesManager
All Implemented Interfaces:
EventListener, BackingStoreManager, BundleActivator, BundleListener, ServiceFactory

public class PreferencesManager
extends Object
implements BundleActivator, BundleListener, ServiceFactory, BackingStoreManager

This activator registers itself as a service factory for the preferences service.


Field Summary
protected  BundleContext context
          The bundle context.
protected  BackingStore defaultStore
          The default store which is used if no service can be found.
protected  ServiceTracker logTracker
          The service tracker for the log service.
protected  Map services
          The map of already created services.
protected  ServiceTracker storeTracker
          The backing store service tracker.
protected  int storeTrackingCount
          Tracking count for the store tracker to detect changes.
 
Constructor Summary
PreferencesManager()
           
 
Method Summary
 void bundleChanged(BundleEvent event)
          Receives notification that a bundle has had a lifecycle change.
protected  void cleanupStore(BackingStore store)
          Clean up the store and remove preferences for deleted bundles.
 Object getService(Bundle bundle, ServiceRegistration reg)
          Creates a new service object.
 BackingStore getStore()
          Return the current backing store.
protected  void log(int level, String message, Throwable t)
           
protected  void save(PreferencesServiceImpl service)
          Save all preferences for this service.
 void start(BundleContext context)
          Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start this bundle.
 void stop(BundleContext context)
          Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop the bundle.
 void ungetService(Bundle bundle, ServiceRegistration reg, Object s)
          Releases a service object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

services

protected final Map services
The map of already created services. For each client bundle a new service is created.


context

protected BundleContext context
The bundle context.


storeTracker

protected ServiceTracker storeTracker
The backing store service tracker.


logTracker

protected ServiceTracker logTracker
The service tracker for the log service.


defaultStore

protected BackingStore defaultStore
The default store which is used if no service can be found.


storeTrackingCount

protected int storeTrackingCount
Tracking count for the store tracker to detect changes.

Constructor Detail

PreferencesManager

public PreferencesManager()
Method Detail

bundleChanged

public void bundleChanged(BundleEvent event)
Description copied from interface: BundleListener
Receives notification that a bundle has had a lifecycle change.

Specified by:
bundleChanged in interface BundleListener
Parameters:
event - The BundleEvent.
See Also:
BundleListener.bundleChanged(org.osgi.framework.BundleEvent)

start

public void start(BundleContext context)
           throws Exception
Description copied from interface: BundleActivator
Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start this bundle. This method can be used to register services or to allocate any resources that this bundle needs.

This method must complete and return to its caller in a timely manner.

Specified by:
start in interface BundleActivator
Parameters:
context - The execution context of the bundle being started.
Throws:
Exception - If this method throws an exception, this bundle is marked as stopped and the Framework will remove this bundle's listeners, unregister all services registered by this bundle, and release all services used by this bundle.
See Also:
BundleActivator.start(org.osgi.framework.BundleContext)

stop

public void stop(BundleContext context)
          throws Exception
Description copied from interface: BundleActivator
Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop the bundle. In general, this method should undo the work that the BundleActivator.start method started. There should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not call any Framework objects.

This method must complete and return to its caller in a timely manner.

Specified by:
stop in interface BundleActivator
Parameters:
context - The execution context of the bundle being stopped.
Throws:
Exception - If this method throws an exception, the bundle is still marked as stopped, and the Framework will remove the bundle's listeners, unregister all services registered by the bundle, and release all services used by the bundle.
See Also:
BundleActivator.stop(org.osgi.framework.BundleContext)

getService

public Object getService(Bundle bundle,
                         ServiceRegistration reg)
Description copied from interface: ServiceFactory
Creates a new service object.

The Framework invokes this method the first time the specified bundle requests a service object using the BundleContext.getService(ServiceReference) method. The service factory can then return a specific service object for each bundle.

The Framework caches the value returned (unless it is null), and will return the same service object on any future call to BundleContext.getService for the same bundle. This means the Framework must not allow this method to be concurrently called for the same bundle.

The Framework will check if the returned service object is an instance of all the classes named when the service was registered. If not, then null is returned to the bundle.

Specified by:
getService in interface ServiceFactory
Parameters:
bundle - The bundle using the service.
reg - The ServiceRegistration object for the service.
Returns:
A service object that must be an instance of all the classes named when the service was registered.
See Also:
ServiceFactory.getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)

ungetService

public void ungetService(Bundle bundle,
                         ServiceRegistration reg,
                         Object s)
Description copied from interface: ServiceFactory
Releases a service object.

The Framework invokes this method when a service has been released by a bundle. The service object may then be destroyed.

Specified by:
ungetService in interface ServiceFactory
Parameters:
bundle - The bundle releasing the service.
reg - The ServiceRegistration object for the service.
s - The service object returned by a previous call to the ServiceFactory.getService method.
See Also:
ServiceFactory.ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)

save

protected void save(PreferencesServiceImpl service)
Save all preferences for this service.

Parameters:
service -

log

protected void log(int level,
                   String message,
                   Throwable t)

getStore

public BackingStore getStore()
Description copied from interface: BackingStoreManager
Return the current backing store.

Specified by:
getStore in interface BackingStoreManager
See Also:
BackingStoreManager.getStore()

cleanupStore

protected void cleanupStore(BackingStore store)
Clean up the store and remove preferences for deleted bundles.

Parameters:
store -


Copyright © 2011 Apache Software Foundation. All Rights Reserved.