This document provides a very brief introduction to writing SilverKing client applications. Example code is shown using the Java API. Other languages are similar.
To illustrate how to write a simple SilverKing application, we will consider the HelloDHT example application. The listing below shows the core of the application. (Full source is here.)
SynchronousNamespacePerspective<String, String> syncNSP;
syncNSP = new DHTClient()
.openSession(GridConfiguration.parseFile(args[0]))
.openSyncNamespacePerspective("_MyNamespace", String.class, String.class);
syncNSP.put("Hello", "world!");
System.out.println(syncNSP.get("Hello"));
The first class that a client must instantiate is a DHTClient. In general, only one client instance
is required irrespective of the number of DHTs, sessions, or namespaces that will be used.
The DHTClient is then used to open a Session to a particular DHT. The DHT is specified using
the name of a GridConfiguration passed in from the command line.
The open Session is then used to open a synchronous "namespace perspective" for the namespace "_MyNamespace".
Namespaces provide a unique key-space for all keys used in SilverKing. Moreover, each namespace
has a set of options associated with it such as where and how the data is stored.
(See Key Concepts and Meta Data Constructs for details.)
In this case, default options are being used and the namespace is being created on the fly.
As SilverKing stores data natively using byte arrays, a namespace perspective maps types from Java
into and out of the namespace.
The synchronous specification means that all operations will block until completion.
Once the SynchronousNamespacePerspective instance is obtained, the client writes a value into the DHT
and immediately reads it out.