com.ibm.tspaces.examples.services
Class TService

java.lang.Object
  |
  +--com.ibm.tspaces.examples.services.TService
Direct Known Subclasses:
Pager, PrintText, SendMail, TstServer

public abstract class TService
extends java.lang.Object
implements java.io.Serializable, Callback

TService is an abstract class that provides support for T Spaces clients that provide some external service to other T Spaces clients. An example of how this might be used is as follows: Assume that we want to have a Service that will wait for a Tuple to arrive that looks like:
["ExternalMail","user@system.com","any long text string"] This new Service will subclass TService and in the constructor it will have something like:

      super(TService.SENDMAIL,"ExternalMail",
                  "This will submit external mail");
      // After any required setup, it should then invoke
      super.enable(); 

 
It will then issue the following T Spaces commands so it can be woken up when anyone sends it work to do.
  	Field stringField = Field.makeField("java.lang.String"); 
		Tuple template = new Tuple("ExternalMail",stringField,stringField);
							
		_TS.eventRegister(	TupleSpace.WRITE, template, this);
     
 
To satisfy the eventRegister, the class must implement Callback and provide a "call" method that will receive the callback. The call method can use the provided putQ and getQ methods to to pass the tuple to the run thread for processing. It should NOT use the callback method to do long running tasks!!!!!!!!!!!!! Before or after issing the eventRegister, it may want to "take" any matching tuples that might have collected while it was not started.

Author:
John Thomas
See Also:
TupleSpace, Serialized Form

Field Summary
static java.lang.String APPLICATION
           
static java.lang.String OTHER
           
static java.lang.String PRINT_FILE
           
static java.lang.String PRINT_TEXT
           
static java.lang.String READMAIL
           
static java.lang.String SENDMAIL
          Possible values for _ServiceType
 
Constructor Summary
TService(java.lang.String type, java.lang.String name, java.lang.String description)
          TService Constructor
 
Method Summary
 boolean enable()
          enable() will activate the service.
 boolean equals(java.lang.Object other)
          Provide a proper equals(Object other) method for TService.
 java.lang.String getName()
          getName will return the name of the Service.
 java.lang.Object getQ()
          Method: getQ() will return the first object in the Queue.
 java.lang.String printQ()
          Give Debug info on Queue
 void putQ(java.lang.Object obj)
          Method: putQ(Object obj) will place specified object into the FIFO Queue
 java.lang.String toString()
          Debug helper that displays the current object status
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SENDMAIL

public static final java.lang.String SENDMAIL
Possible values for _ServiceType

PRINT_TEXT

public static final java.lang.String PRINT_TEXT

PRINT_FILE

public static final java.lang.String PRINT_FILE

READMAIL

public static final java.lang.String READMAIL

APPLICATION

public static final java.lang.String APPLICATION

OTHER

public static final java.lang.String OTHER
Constructor Detail

TService

public TService(java.lang.String type,
                java.lang.String name,
                java.lang.String description)
TService Constructor
Method Detail

getName

public java.lang.String getName()
getName will return the name of the Service.

enable

public boolean enable()
enable() will activate the service. It will write a registration Tuple to the TupleSpace giving the name and description of the service.

equals

public boolean equals(java.lang.Object other)
Provide a proper equals(Object other) method for TService. This will return true if all of the following conditions are true:
- (Object other) is an instance of TService
- The ServiceNames match i.e. this.getName.equals(other.getName()
Overrides:
equals in class java.lang.Object
Parameters:
Object - other is the TService object to compare this to

toString

public java.lang.String toString()
Debug helper that displays the current object status
Overrides:
toString in class java.lang.Object

getQ

public java.lang.Object getQ()
Method: getQ() will return the first object in the Queue.

If the queue is empty, it will block until a new object arrives.

Returns:
Object It will return the next Object in the Queue.

putQ

public void putQ(java.lang.Object obj)
Method: putQ(Object obj) will place specified object into the FIFO Queue
Parameters:
obj - An Object that is to be added to the queue.
Returns:
void

printQ

public java.lang.String printQ()
Give Debug info on Queue