org.jcsp.win32
Class NTService

java.lang.Object
  extended by org.jcsp.win32.NTService
Direct Known Subclasses:
SpawnerServiceNT, TCPIPCNSServerNT

public abstract class NTService
extends Object

Abstract class for declaring an NT service. A Java implementation of a service must declare the startService and stopService methods. startService must run the actual service and must block until the service is ready to terminate. For example it may sit in a loop servicing requests. stopService will be called when startService is expected to stop blocking and return. The stopService method should return promptly. Any time consuming shutdown code should be done asynchronously (for example in the startService thread) before startService returns.

For example:

 public class MyService extends NTService {
   boolean running = true;
   protected void startService () {
     while (running) {
       System.beep ();
       Thread.sleep (1000);
     }
   }
   protected void stopService () {
     running = false;
   }
   private MyService () {
     super ("MyService");
   }
   public static void main (String[] args) {
     new MyService ().run ();
   }
 }
 

Author:
Quickstone Technologies Limited

Constructor Summary
protected NTService(String serviceName)
          Creates a new NT service wrapper with the given name.
 
Method Summary
protected  void run()
          Runs the service, registering it with the NT service dispatcher.
protected abstract  void startService()
          This will be called when the service is started and must block until the service completes.
protected abstract  void stopService()
          This will be called when the service is stopped and the startService method must terminate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NTService

protected NTService(String serviceName)
Creates a new NT service wrapper with the given name. This name ought to match the name that is registered with the NT service manager but probably will work if it doesn't. What is more important is that the name is system unique.

Method Detail

startService

protected abstract void startService()
This will be called when the service is started and must block until the service completes.


stopService

protected abstract void stopService()
This will be called when the service is stopped and the startService method must terminate.


run

protected final void run()
Runs the service, registering it with the NT service dispatcher. If there is a problem this will terminate the JVM with the Windows error code. If all is okay, this will never return. All subsequent processing is done by the allocated StarterThread and StopperThread objects and threads internal to the DLL.



Copyright © 1996-2012. All Rights Reserved.