summaryrefslogtreecommitdiff
path: root/java/JACE/ServiceConfigurator/ServiceObject.java
blob: 4538698e8a6e891ecf158c85e1ca41fe207c43f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*************************************************
 *
 * = PACKAGE
 *    JACE.ServiceConfigurator
 *
 * = FILENAME
 *    ServiceObject.java
 *
 *@author Prashant Jain
 *@author Everett Anderson
 *
 *************************************************/
package JACE.ServiceConfigurator;

import java.io.*;
import JACE.ASX.*;
import JACE.Reactor.*;

/**
 * Provides a default implementation of the Service interface, and can also
 * be registered with the Reactor.
 *
 *@see JACE.Reactor
 *@see Service
 */
public class ServiceObject implements EventHandler, Service
{
  /**
   * Initialize object when dynamic loading occurs. Overwrite this
   * method to do anything useful. 
   *@return -1 (default implementation)
   */
  public int init (String [] args)
  {
    return -1;
  }

  /** 
   * Terminate the object. Note that an object can not be explicitly
   * unloaded. Overwrite this method to do anything useful.
   *@return -1 (default implementation)
   */
  public int fini ()
  {
    return -1;
  }

  /**
   * Get information on an active object. Overwrite this method to do
   * anything useful. 
   *@return null (default implementation)
   */
  public String info ()
  {
    return null;
  }

  /** 
   * Called when timer expires. Overwrite this method to do
   * anything useful. 
   *@param tv Time Value for when timer expired
   *@param obj An arbitrary object that was passed to the Timer Queue
   * (Asynchronous Completion Token)
   *@return -1
   */
  public int handleTimeout (TimeValue tv, Object obj)
  {
    return -1;
  }

  /**
   * Request that this service suspend activity.  Overwrite this
   * method to do anything useful.  Currently, this sets an internal
   * state variable to true.
   */
  public int suspend () 
  {
    this.suspended_ = true;

    return 0;
  }

  /**
   * Request that this service resume activity.  Currently, this sets
   * an internal state variable to false.
   */
  public int resume ()
  {
    this.suspended_ = false;

    return 0;
  }

  /**
   * Is this service suspended? 
   */
  public boolean suspended ()
  {
    return this.suspended_;
  }

  /**
   * Return the name of the Service.  Implementation provided.
   */
  public String name ()
  {
    return this.name_;
  }

  /**
   * Set the name of the Service.  Should be called when a Service is
   * created -- this is done automatically by ServiceConfig when loading
   * from a file.  Implementation provided.
   */
  public void name (String name)
  {
    this.name_ = name;
  }

  /**
   * Name of this ServiceObject.
   */
  protected String name_ = null;

  /**
   * Status of whether this ServiceObject is suspended or not.
   * (Initially false)
   */
  protected boolean suspended_ = false;
}