All Packages  This Package  Class Hierarchy  Class Search  Index

Class com.syncbuilder.service.ServiceBase
java.lang.Object
   |
   +----com.syncbuilder.service.ServiceBase

  Summary

public abstract class  ServiceBase
     extends java.lang.Object
     implements com.syncbuilder.service.ServiceControlListener, 
                java.lang.Runnable
{
          // Constructors 1
     public ServiceBase();

          // Methods 8
     public synchronized void addServiceStateListener(ServiceStateListener);
     public void addThread(Thread);
     public void removeServiceStateListener(ServiceStateListener);
     public synchronized void resume();
     public void run();
     public synchronized void start();
     public synchronized void stop();
     public synchronized void suspend();
}

This class is meant to be a suitable basis for most implementations of a service that implements ServiceControlListener.
You will only have to implement the service()-method, which will be invoked continuously in the service's main loop.
You may also implement the init()-method which will be invoked anytime the service is started, and the destroy()-method which will be invoked anytime the service is stopped.

See the Java Tutorial from JavaSoft if you wish to understand the way in which I start, stop, suspend, and resume the Thread.

Another very valuable facility of ServiceBase is its time-slicing facility. Any thread you register with the ServiceBase through the addThread()-method will be added to a pool of threads which are controlled through a time-slicing scheduler. This will avoid thread-starvation on systems which use green-threads.


  Cross Reference

Extended By:
SyncServer





  Constructors

· ServiceBase

Summary  |  Top
   public ServiceBase() 


  Methods

· run

Summary  |  Top
   public void run() 

This is the implementation of the run()-method from the Runnable-interface.
It will go through three distinct stages:
1. Initialization (invocation of init())
2. Providing service, until stopped (continuous invocations of service())
3. Release of occupied resources (invocation of destroy())

Implements:
run in interface Runnable


· suspend

Summary  |  Top
   public synchronized void suspend() 

Temporarily halt the service. This will not release any resources and the service will be able to resume operation very quickly.



· resume

Summary  |  Top
   public synchronized void resume() 

Resume operation of the service after it has been suspended. This is a very quick operation, because all the resources that the service needs are still allocated.



· start

Summary  |  Top
   public synchronized void start() 

Start the service. This will switch the service into a fully operational state.
Starting a service will reserve all resources for that service and might therefore be an expensive operation.



· stop

Summary  |  Top
   public synchronized void stop() 

Stop the service. This will switch the service into a completely unready state. It will release all allocated resources and it will have to be restarted in order to run again. Restarting the service from a stopped state may be an expensive operation.



· addThread

Summary  |  Top
   public void addThread(Thread thread) 

Add a thread to the time-slicing scheduler. The time-slicer will take complete control over the threads priority, and you should NOT touch the priority after adding the thread to the time-slicer.



· addServiceStateListener

Summary  |  Top
   public synchronized void addServiceStateListener(ServiceStateListener sscl) 


· removeServiceStateListener

Summary  |  Top
   public void removeServiceStateListener(ServiceStateListener sscl) 


All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7