Creating Adapters


Why create a new adapter? 

Adapters are typically created in order to support a new tuple space implementation through the same interface used by LighTS, so that the code written once for LighTS can actually work with several other implementations. 

How to create an adapter? 

Creating an adapter actually means to create four new classes, namely, a TupleSpaceFactory class, which must extend lights.adapters.TupleSpaceFactory, and other three classes (typically called FieldAdapter, TupleAdapter, and TupleSpaceAdapter) that implement the IField, ITuple, ITupleSpace interfaces
Typically, all these classes are placed in a new package, e.g.,
lights.adapters.myadapter. Thus, for instance, lights.adapters.tspaces is the package containing adapters for the last version of TSpaces. 

TupleSpaceFactory is the class that determines the 

 

Each of these classes implements the methods of the corresponding interface by calling one or more methods of the implementation they adapt. For instance, the implementation of the method out in lights.adapters.tspaces.TupleSpaceAdapter is the following:

public void out(ITuple tuple) throws TupleSpaceException {
  try {
    impl.write(TupleAdapter.unwrap(tuple));
  } catch(com.ibm.tspaces.TupleSpaceException e) {
    throw new lights.interfaces.TupleSpaceException(e);
  }
}

A few things are worth noting in the above code fragment: