HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"JavaNT Services"
Volume: 4 Issue: 2, p. 54

	

Listing 1.

import java.lang.*;
import java.io.*;
import java.util.*;
import com.ms.service.Service;
import YOURSERVICE;
public class Linking extends com.ms.service.Service{ 

 YOUR MEMBER VARIABLES{ One of which should be an Object of the type YOURSERVICE}

 YOURSERVICE ys;




 static
    {
 // Uncomment to disable the assassin.  The service will fail to respond
 // in the time specified in the last waithint for the third pause
// event received.  If the assassin is enabled (i.e. this line is 
// commented
 // out, the default), then the service will be forcibly killed.

 Service.disableassassin = true;
    }



 public Linking(){
   System.out.println("Entered Linking");
   YOURSERVICE ys = new YOURSERVICE();
   String argsin[] = new String[1];
   argsin[0] = "-someargument";
   System.out.println("made YS argument string of "+argsin[0]);
   ys.main(argsin);
   System.out.println("called YSmain");
   System.out.println("Sending updated pending status");
        CheckPoint(1000);
   System.out.println("setting Running");
   setRunning(ACCEPT_STOP|ACCEPT_PAUSE_CONTINUE);
   System.out.println("post setRunning in Linking");
 }

protected boolean handleStop (){
 Thread currentT;
 Thread[]  iterT;
 ThreadGroup tg;
 int howmany;


 currentT = Thread.currentThread();
 tg = currentT.getThreadGroup();
 howmany = tg.activeCount();
 iterT = new Thread[howmany];
 tg.enumerate(iterT);
 System.out.println("there are "+howmany+" threads");


 for (int iter=1;iter<4;iter++){
  String name = iterT[iter].getName();
  String is = iterT[iter].toString();
  System.out.println("Attempting to stop thread number "+iter+"called : "+name+" which is
   "+is);
  try{
   iterT[iter].stop();
  }catch (Error e){
   System.out.println("Thread threw error :"+e);
  }
 }
 setStopping(5000);
 System.out.println("dying");
 rt.exit(0);
return super.handleStop();
     }

    protected boolean handlePause (){
  pausecount++;
 if (pausecount == 3)
  {
       System.out.println("pause #3, sleeping for 30 seconds, should be killed in 2+5
	    seconds");
       setPausing(2000);
       try{
    Thread.sleep(30000);
       }
   catch(InterruptedException e){
    System.out.println("interrupted");
       }
  }
  else
  {
       System.out.println("received pause #"+pausecount+", pausing for 2 seconds");
       setPausing(5000);
       try{
    Thread.sleep(2000);
       }
       catch (InterruptedException e){
    System.out.println("interrupted");
       }
       System.out.println("sending paused");
       setPaused();
       System.out.println("sent paused");
  }
  return false;
     }

    protected boolean handleContinue (){
  System.out.println("received continue, continuing after 2 seconds");
  setContinuing(5000);
  try
  {
      Thread.sleep(2000);
 }
  catch (InterruptedException ei)
  {
      System.out.println("interrupted");
  }
  System.out.println("sending running");
  setRunning();
  System.out.println("sent running after continue");
  return false;
    }

    protected boolean handleShutdown (){
  System.out.println("received shutdown, treating as stop");
  return handleStop();
    }

   

protected boolean handleInterrogate (){
  System.out.println("received interrogate");
  setServiceStatus(getServiceStatus());
 System.out.println("sent status for interrogate");

 intcount++;
 if (intcount == 3){
      System.out.println("received 3rd interrogate, stopping self in 5 seconds");
       try{
    Thread.sleep(5000);
       }
       catch (InterruptedException iex){
    System.out.println("interrupted");
       }
       System.out.println("stopping");
       StoyserviceEventHandler(1000);
  }
 return false;
     }
}//end class Linking


 
      
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.