Java Reference
In-Depth Information
{
this.context = c;
startClient();
c.addServiceListener(this);
}
public void stop(BundleContext c) throws Exception
{
stopClient(true);
c.removeServiceListener(this);
}
public void serviceChanged(ServiceEvent event)
{
switch(event.getType())
{
case ServiceEvent.REGISTERED:
startClient();
break;
case ServiceEvent.UNREGISTERING:
stopClient(false);
break;
case ServiceEvent.MODIFIED:
stopClient(false);
startClient();
break;
default:
}
}
private void startClient()
{
ServiceReference<Counter> ref =
context.getServiceReference(Counter.class);
if(ref != null)
{
Counter hello = (Counter) context.getService(ref);
if(hello != null)
{
if(thread == null)
{
thread = new CounterThread(hello);
thread.start();
}
}
}
}
private void stopClient(boolean uncoditionally)
{
ServiceReference<Counter> ref =
context.getServiceReference(Counter.class);
if(uncoditionally || ref == null)
{
if(thread != null)
{
thread.interrupt();
try
 
Search WWH ::




Custom Search