ibm tspaces lab 1
Skip this Video
Download Presentation
IBM TSpaces Lab 1

Loading in 2 Seconds...

play fullscreen
1 / 19

IBM TSpaces Lab 1 - PowerPoint PPT Presentation

  • Uploaded on

IBM TSpaces Lab 1. Introduction. Summary. TSpaces Overview Basic Definitions Basic primitive operations Reading/writing tuples in tuplespace HelloWorld program Installing TSpaces Compiling/running programs in TSpaces. TSpaces Overview.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'IBM TSpaces Lab 1' - gabriel-merritt

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
ibm tspaces lab 1

IBM TSpacesLab 1


  • TSpaces Overview
  • Basic Definitions
  • Basic primitive operations
  • Reading/writing tuples in tuplespace
  • HelloWorld program
  • Installing TSpaces
  • Compiling/running programs in TSpaces
tspaces overview
TSpaces Overview
  • TSpaces is a Java implementation of the Linda coordination model. It enables communication between applications and devices in a network of heterogeneous computers and operating systems.
basic definitions
Basic Definitions
  • Field
    • Most basic component of Tuplespace data structure. It contains:
      • Type (i.e. "java.lang.String" or "")
      • Value
      • Field Name (optional): Specifying a field name implies that this field will be indexed (and searched).
basic definitions 2
Basic Definitions (2)
  • Tuple
    • A Tuple object is an ordered sequence of Fields.
    • Implemented by SuperTuple class (abstract class)
    • Clients should create objects of either Tuple or SubclassableTuple classes.
    • A template tuple is a Tuple that is used for matching. One or more of the Fields in a template may be "wildcards" and consist of only the class type with no value.
basic definitions 3
Basic Definitions (3)
  • TupleSpace
    • A class implementing a space where tuples can be added/removed
    • It is stored and administered across a network on one or more "TSpace Servers“. A TSpace server may contain many Tuplespaces.
    • Several threads on the same or different machines can be accessing the space simultaneously.
    • For each different TupleSpace a client wishes to access, it requires a separate instance of this class, even if they are managed by the same server.
    • In order to obtain an instance of a specific tuplespace you need the name of the space, and the name of a server that manages that space.
basic primitive operations
Basic primitive operations
  • write ( tuple ): Adds a tuple to the space.
  • take( template_tuple ): Searches for a tuple that matches the template. When found, the tuple is removed from the space and returned. If none is found, returns null.
  • waitToTake(template_tuple ): Searches for a tuple that matches the template. Blocks until match is found. Removes and returns the matched tuple from the space.
  • read( template_tuple ): Like "take" above, except that the tuple is not removed from the tuple space.
basic primitive operations 2
Basic primitive operations (2)
  • waitToRead( template_tuple ): Like "waitToTake" above, except that the tuple is not removed from the tuple space.
  • scan( template_tuple ): Like "read" above, except that it returns the entire set of tuples that match.
  • countN( template_tuple ): Like "scan" above, except that it returns the number of matching tuples rather than the set of tuples itself.

There are also numerous other more specialized

commands and there is an ability to define your own

specialized commands.

reading and writing tuples
Reading and writing tuples

Step 1: Create a new tuplespace or get access to an already

created tuplespace

String host = "";


TupleSpace ts = new TupleSpace("Example1",host);

The above will contact the TSpaces server that is running on a machine with hostname "" and return a handle to the TupleSpace that is named "Example1". If the "Example1" TupleSpace does not exist, it will be created at this time.

reading and writing tuples 2
Reading and writing tuples (2)

Step 2: Create and write tuples to tuplespace

Tuple t1 = new Tuple("Key1","Data1");


Tuple t2 = new Tuple("Key2",new Integer(999),"Data2");


Tuple t3 = new Tuple("Key2","Data3");


The above will create and write 3 Tuples to the TupleSpace allocated previously. Tuples can contain any number and any type of fields.

reading and writing tuples 3
Reading and writing tuples (3)

Other ways to create and write a tuple are the


Field f1 = new Field("Key1");

Field f2 = new Field("Data1");

Tuple t1 = new Tuple();





ts.write("Key1","Data1"); .

reading and writing tuples 4
Reading and writing tuples (4)

Step 3: Reading tuples from tuplespace

In order to read a tuple you must create a template Tuple.

Template Tuple is a Tuple that is used to select matching Tuples.

It will contain 0 or more Fields that are either Actual Fields or

Formal Fields.

  • Actual fields have a value that must be matched exactly against the corresponding Fields in the tuples that are in the TupleSpace.
  • Formal fields have a class but no value and only describe the type of value that is to be returned. Basically they act as wildcards.
reading and writing tuples 5
Reading and writing tuples (5)

Tuple template = new Tuple("Key2", new


Tuple tuple =;

String data = (String)tuple.getField(1).getValue();

The above code creates a template that matches any tuple having two fields of type String. The first field must contain the value "Key2". The second field can match any field of String type. In order to read the matching Tuples from Tuplespace we use the command read. The command take can also be used but it will remove the matching Tuples from the TupleSpace database and return it to the caller.

helloworld example
HelloWorld Example



public class HelloWorld {

public static void main(String[] args) {

String myName = "World";

boolean needReply = false;

if ( args.length > 0)

myName = args[0];

try {

TupleSpace space = new TupleSpace();

Tuple template = new Tuple(myName,

new Field(String.class),new


helloworld example 2
HelloWorld Example (2)

System.out.println("Checking for message in tuplespace...");

Tuple msg = space.take(template);

if ( msg == null) {

System.out.println("No message for me!\n

Sendingmessage to World...");

msg = new Tuple("World", myName,"Hello World");

needReply = true;


} else {

System.out.println("Message received is: "+msg);

System.out.println("Sending reply message to : "+


helloworld example 3
HelloWorld Example (3)

msg = newTuple((String)msg.getField(1).getValue(),




if (needReply) { // Wait for a reply

System.out.println("Waiting for reply ...");

msg = space.waitToTake(template);

System.out.println("Message received is: "+msg);


} catch (Exception e) {





installing tspaces
Installing Tspaces
  • Download TSpaces package ( from here
  • Unzip package to a directory tspaces
  • Exit to dos command window and change directory to tspaces
  • In order to start a TSpaces Server execute command: bin\tspaces

If server is started successfully the promptTSServer:>is appeared

  • In order to stop the TSpaces Server execute command exit
compiling running programs
Compiling/running programs

In order to compile and run TSpaces programs you need to

include the jar files tspaces_client.jar and tspaces.jar in your

CLASSPATH. These files are located in the tspaces_dir\lib (where

tspaces_dir is the path to the directory where TSpaces is installed).


javac -classpath .;tspaces_dir\lib\tspaces_client.jar; tspaces_dir\lib\tspaces.jar


java -cp .;tspaces_dir\lib\tspaces_client.jar; tspaces_dir\lib\tspaces.jar yourfile

Replace tspaces_dir with the path to the directory where TSpaces

is installed.

Compile and run the HelloWorld Example

http server interface
HTTP Server Interface
  • The TSpaces Server contains a light built-in HTTP Server. You can use this interface to determine the status of TSpaces or obtain debug information.
  • In order to obtain this information access HTTP server at http://hostname:8201/debug where hostname is the name of the machine that TSpaces server runs.