home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / sdk20 / jsdk03.cab / Bin / jntsvc / TestService.java < prev   
Encoding:
Java Source  |  1997-09-25  |  3.5 KB  |  137 lines

  1. // TestService.java
  2. //
  3. // (C)Copyright 1997 Microsoft Corporation, All rights reserved.
  4. //
  5.  
  6. import java.io.*;
  7. import com.ms.service.*;
  8.  
  9. public
  10. class TestService extends Service
  11. {
  12.     static
  13.     {
  14.         // Uncomment to disable the assassin.  The service will fail to respond 
  15.         // in the time specified in the last waithint for the third pause
  16.         // event received.  If the assassin is enabled (i.e. this line is commented
  17.         // out, the default), then the service will be forcibly killed.
  18.         
  19.         //Service.disableassassin = true;
  20.     }
  21.  
  22.     int pausecount;
  23.     int intcount;
  24.  
  25.     public TestService (String[] args) throws IOException
  26.     {
  27.         System.out.println("Sending updated pending status");
  28.  
  29.         CheckPoint(1000);
  30.  
  31.         System.out.println("Sending running status with all controls");
  32.  
  33.         setRunning(ACCEPT_SHUTDOWN | ACCEPT_PAUSE_CONTINUE | ACCEPT_STOP);
  34.         
  35.         System.out.println("Started");
  36.     }
  37.  
  38.     protected
  39.     boolean handleStop ()
  40.     {
  41.         setStopping(5000);
  42.         System.out.println("dying");
  43.         return true;
  44.     }
  45.  
  46.     protected
  47.     boolean handlePause ()
  48.     {
  49.         pausecount++;
  50.         if (pausecount == 3)
  51.         {
  52.             System.out.println("pause #3, sleeping for 30 seconds, should be killed in 2+5 seconds");
  53.             setPausing(2000);
  54.             try
  55.             {
  56.                 Thread.sleep(30000);
  57.             }
  58.             catch (InterruptedException e)
  59.             {
  60.                 System.out.println("interrupted");
  61.             }
  62.         }
  63.         else
  64.         {
  65.             System.out.println("received pause #"+pausecount+", pausing for 2 seconds");
  66.             setPausing(5000);
  67.             try
  68.             {
  69.                 Thread.sleep(2000);
  70.             }
  71.             catch (InterruptedException e)
  72.             {
  73.                 System.out.println("interrupted");
  74.             }
  75.             System.out.println("sending paused");
  76.             setPaused();
  77.             System.out.println("sent paused");
  78.         }
  79.  
  80.         return false;
  81.     }
  82.  
  83.     protected
  84.     boolean handleContinue ()
  85.     {
  86.         System.out.println("received continue, continuing after 2 seconds");
  87.         setContinuing(5000);
  88.         try
  89.         {
  90.             Thread.sleep(2000);
  91.         }
  92.         catch (InterruptedException e)
  93.         {
  94.             System.out.println("interrupted");
  95.         }
  96.         System.out.println("sending running");
  97.         setRunning();
  98.         System.out.println("sent running after continue");
  99.  
  100.         return false;
  101.     }
  102.  
  103.     protected
  104.     boolean handleShutdown ()
  105.     {
  106.         System.out.println("received shutdown, treating as stop");
  107.         return handleStop();
  108.     }
  109.  
  110.     protected
  111.     boolean handleInterrogate ()
  112.     {
  113.         System.out.println("received interrogate");
  114.         setServiceStatus(getServiceStatus());
  115.         System.out.println("sent status for interrogate");
  116.         
  117.         intcount++;
  118.         if (intcount == 3)
  119.         {
  120.             System.out.println("received 3rd interrogate, stopping self in 5 seconds");
  121.             try
  122.             {
  123.                 Thread.sleep(5000);
  124.             }
  125.             catch (InterruptedException iex)
  126.             {
  127.                 System.out.println("interrupted");
  128.             }
  129.             System.out.println("stopping");
  130.             StopServiceEventHandler(1000);
  131.         }
  132.         
  133.         return false;
  134.     }
  135. }
  136.  
  137.