com.ibm.tspaces.examples.services
Class PrintText
java.lang.Object
|
+--com.ibm.tspaces.examples.services.TService
|
+--com.ibm.tspaces.examples.services.PrintText
- public class PrintText
- extends TService
- implements Callback, java.lang.Runnable
PrintText accepts "PrintText"" requests from TupleSpace and
issues a specified command to send the specified text to
the printer
The PrintText service is started by issuing the java invocation and
specifying the PrinterName, PrintCommand and FileDirectory as parameters
java com.ibm.tspaces.examples.services.PrintText
NOTE: When John started this, he used the following command:
Printer1 "prfile32 /q " "c:\\tmp"
but now that we want to make this a more general service, we
just want to make this a general command, like this:
Printer1 "print c:\\tmp"
A client that wants to use the services needs to only do the following
TupleSpace servers = new TupleSpace("Services",servicehost);
servers.write(TService.PRINT_TEXT, Printer1,"Line1 \n Line2");
The above is the simple PrintText command.
The client can optionally add both fields to send Printer Options
and an ID value that is used to get back a return value that will
indicate if the request was sucessful.
A client that wants to print the contents of a file needs to specify
the File as a URL and pass it via the URLCopy facility
TupleSpace servers = new TupleSpace("Services",servicehost);
servers.write(TServices.PRINT,Printer1,
new URLCopy(filepath)),"opts",new Long(id));
where "filepath" points to a printable file. This could also
be in the form "file:/filepath/filename" or "http://server/file"
- Author:
- John Thomas
- See Also:
TupleSpace, Serialized Form
|
Constructor Summary |
PrintText(java.lang.String name,
java.lang.String cmd,
java.lang.String filedir,
java.lang.String filename)
PrintText Constructor |
|
Method Summary |
boolean |
call(java.lang.String eventName,
java.lang.String tsName,
int seqNum,
SuperTuple tuple,
boolean isException)
Implementation for the Callback interface. |
static void |
main(java.lang.String[] argv)
Startup the PrintText Service Client. |
void |
print(java.lang.String text,
java.lang.String opts,
java.lang.Long ack)
The print(msg) method will place the string data into a file and
then issue the specified print command. |
void |
printfile(URLCopy clientCopy,
java.lang.String opts,
java.lang.Long ack)
The printfile method will get the file data from the
the url and place it in the directory and
then issue the specified print command. |
void |
run()
The run() method will wait for a print request Tuple to be Queued
It will then take the request from TSpaces and then invoke the
print method to Print the text that is included in the Tuple. |
| Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
PrintText
public PrintText(java.lang.String name,
java.lang.String cmd,
java.lang.String filedir,
java.lang.String filename)
- PrintText Constructor
call
public boolean call(java.lang.String eventName,
java.lang.String tsName,
int seqNum,
SuperTuple tuple,
boolean isException)
- Implementation for the Callback interface.
- Specified by:
- call in interface Callback
- Parameters:
eventName_ - the name of the event command that caused this call, that is the
name of the client side command of the thread that registered this call, e.g., in the
case of a read, this would be TupleSpace.READ, **not** TupleSpace.WRITE which is the
corresponding command that caused the actaul event.tsName_ - the name of the tuple space this command was executed on.sequenceNumber_ - the sequenceNumber for this event/commandtuple_ - the returned tuple or a Tuple with an exception insideisException_ - was the command processed normaly or was there an exception- Returns:
- true if this is the last call this sequence # should be getting otherwise false
run
public void run()
- The run() method will wait for a print request Tuple to be Queued
It will then take the request from TSpaces and then invoke the
print method to Print the text that is included in the Tuple.
- Specified by:
- run in interface java.lang.Runnable
print
public void print(java.lang.String text,
java.lang.String opts,
java.lang.Long ack)
- The print(msg) method will place the string data into a file and
then issue the specified print command.
printfile
public void printfile(URLCopy clientCopy,
java.lang.String opts,
java.lang.Long ack)
- The printfile method will get the file data from the
the url and place it in the directory and
then issue the specified print command.
main
public static void main(java.lang.String[] argv)
- Startup the PrintText Service Client.
Syntax:
java ...PrintText name "cmd to issue" filedir
name = Name to be used to contact server
cmd = Print command to use. File name will be appended
filedir = Directory where file will be built during print.