org.apache.felix.examples.dictionaryclient2
Class Activator

java.lang.Object
  extended by org.apache.felix.examples.dictionaryclient2.Activator
All Implemented Interfaces:
EventListener, BundleActivator, ServiceListener

public class Activator
extends Object
implements BundleActivator, ServiceListener

This class implements a bundle that uses a dictionary service to check for the proper spelling of a word by checking for its existence in the dictionary. This bundle is more complex than the bundle in Example 3 because it monitors the dynamic availability of the dictionary services. In other words, if the service it is using departs, then it stops using it gracefully, or if it needs a service and one arrives, then it starts using it automatically. As before, the bundle uses the first service that it finds and uses the calling thread of the start() method to read words from standard input. You can stop checking words by entering an empty line, but to start checking words again you must stop and then restart the bundle.

Author:
Felix Project Team

Constructor Summary
Activator()
           
 
Method Summary
 void serviceChanged(ServiceEvent event)
          Implements ServiceListener.serviceChanged().
 void start(BundleContext context)
          Implements BundleActivator.start().
 void stop(BundleContext context)
          Implements BundleActivator.stop().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Activator

public Activator()
Method Detail

start

public void start(BundleContext context)
           throws Exception
Implements BundleActivator.start(). Adds itself as a listener for service events, then queries for available dictionary services. If any dictionaries are found it gets a reference to the first one available and then starts its "word checking loop". If no dictionaries are found, then it just goes directly into its "word checking loop", but it will not be able to check any words until a dictionary service arrives; any arriving dictionary service will be automatically used by the client if a dictionary is not already in use. Once it has dictionary, it reads words from standard input and checks for their existence in the dictionary that it is using. (NOTE: It is very bad practice to use the calling thread to perform a lengthy process like this; this is only done for the purpose of the tutorial.)

Specified by:
start in interface BundleActivator
Parameters:
context - the framework context for the bundle.
Throws:
Exception

stop

public void stop(BundleContext context)
Implements BundleActivator.stop(). Does nothing since the framework will automatically unget any used services.

Specified by:
stop in interface BundleActivator
Parameters:
context - the framework context for the bundle.

serviceChanged

public void serviceChanged(ServiceEvent event)
Implements ServiceListener.serviceChanged(). Checks to see if the service we are using is leaving or tries to get a service if we need one.

Specified by:
serviceChanged in interface ServiceListener
Parameters:
event - the fired service event.


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.