Space-Client-Package

Das Space-Client-Package stellt ein API zur Verfügung, mit dem man das Space-System (siehe Space) benutzen kann. Die elementaren Interfaces sind dabei Entry, Space, Transaction und Lease.


Entry

Das Entry-Interface beinhaltet die folgenden Methoden:

• public Enumeration getClassNames();
• public Enumeration getSuperClassNames();
• public boolean isAssignableTo(String classname);
• public Enumeration getFields();
• public void setValue(String field, Sexpression value);
• public Sexpression getValue(String field);
• public List toList();

Entries sind die Datenobjekte, die im Space-System gespeichert und verarbeitet werden können. Entries sind Instanzen einer oder mehreren Entry-Klassen (Multiple Characterization), deren Namen mit getClassNames ermittelt werden können. GetSuperClassNames ermittelt die Namen aller Superklassen, deren Instanz das Entry implizit ist. IsAssignableTo überprüft, ob das Entry eine Instanz der angegebenen Klasse ist. Entries haben durch Zeichenketten benannte Attibute, deren Werte S-Expressions (siehe Lisp) sein müssen. GetFields ermittelt die Namen aller Attribute. Mit SetValue kann ein Attributwert gesetzt werden. GetValue ermittelt einen Attributwert.

Erzeugt werden Entries von einer EntryFactory.


Space

Das Space-Interface stellt die folgenden Methoden bereit:

• public Object isAlive();
• public TransactionAndLease createTransaction(long timeout) throws LeaseDeniedException;
• public EventRegistration notify(Entry tmpl, Transaction txn, RemoteEventListener listener, long timeout) throws TransactionException;
• public Entry read(Entry tmpl, Transaction txn, long timeout) throws TransactionException, InterruptedException;
• public Entry readIfExists(Entry tmpl, Transaction txn, long timeout) throws TransactionException, InterruptedException;
• public Entry[] readAllIfExist(Entry tmpl, Transaction txn, long timeout) throws TransactionException, InterruptedException;
• public Entry take(Entry tmpl, Transaction txn, long timeout) throws TransactionException, InterruptedException;
• public Entry takeIfExists(Entry tmpl, Transaction txn, long timeout) throws TransactionException, InterruptedException;
• public Lease write(Entry entry, Transaction txn, long timeout) throws TransactionException;
• public Sexpression call(List libraries, List activity, Transaction txn, long timeout) throws TransactionException, CannotEvalException;

IsAlive liefert einen Wert ungleich null, wenn das Space-System online ist. CreateTransaction erzeugt eine Transaktion und ein dazugehörendes Lease. Wenn das Lease nicht verlängert wird, wird die Transaktion nach dessen Ablauf automatisch zurückgerollt. Notify registriert einen RemoteEventListener. Der Listener erhält einen Event, wenn ein Entry, das auf das Template passt, angelegt oder gelöscht wird. Read, ReadIfExists und ReadAllIfExist lesen ein oder mehrere Entries, die auf das Template passen. Take und TakeIfExists entnehmen Entries aus dem Space. Write schreibt ein neues Entry in den Space. Der Rückgabewert ist ein Lease für das Entry. Läuft das Lease ab, wird das Entry automatisch wieder aus dem Space gelöscht. Mit Call können Funktionen aufgerufen werden, die im Space ausgeführt werden.

Eine Instanz eines Objekts, das das Space-Interface implementiert, kann man wie folgt erhalten:

import facade.ConnectionFactory;
import space.Space;
import space.SpaceFactory;
// ...
String host = "<host>";
int port = <port>;
ConnectionFactory connectionfactory = new ConnectionFactory();
SpaceFactory spacefactory = new SpaceFactory(connectionfactory);
Space space = spacefactory.createSpace(host, port);


Transaction

Das Transaction-Interface ermöglicht das Festschreiben oder Zurückrollen von Transaktionen:

• public void abort() throws UnknownTransactionException, CannotAbortException;
• public void abort(long timeout) throws UnknownTransactionException, TimeoutExpiredException, CannotAbortException;
• public void commit() throws UnknownTransactionException, CannotCommitException;
• public void commit(long timeout) throws UnknownTransactionException, TimeoutExpiredException, CannotCommitException;


Lease

Mit dem Lease-Interface können Leases verlängert oder vorzeitig beendet werden:

• public long getExpiration();
• public void renew(long duration) throws LeaseDeniedException, UnknownLeaseException;
• public void cancel() throws UnknownLeaseException;


Die Quelltexte unterliegen der Modified Artistic License v1 und finden sich in der Version v202 in der unten verlinkten Jar-Datei unter dem Namen spaceclientsrc.jar.

Zusätzlich werden noch das Collections-Package, das Lisp-Package, das Property-Set-Package, das Threads-Package und das XML-Utils-Package benötigt.


spaceclientsrc.jar