Starting a Server


All CORK-based applications require that a server object be created to listen for client connections, manage persistent copies of replicated objects, handle requests for replicated object retrieval, and process modifications to replicated objects. The key components of the CORK server are the same across all CORK-based applications. This example below shows how to write a simple CORK server application.
The standard CORK server implementation is class edu.vt.cs.collab.cork.impl.inet.ServerImpl. This class uses file-based storage and listens for both HTTP and TCP connections. Its constructor requires five arguments:
  • A port to listen on. The server will actually listen on a series of ports (for different kinds of connections) starting with the port given in the constructor. (This will likely change in a future release to allow explicit assignment of ports for each protocol.)
  • The name (path) of a directory to store persistent copies of objects in. This directory will be created if it does not exist.
  • The depth of the storage directory structure. The file-based storage mechanism will hash objects across multiple directories based on this parameter. The hashing uses (decimal) digits taken from CORK ObjectIDs. If this value is 0, all objects will be put into a single directory. If it is 1, objects will be hashed by type, with one directory per object class. If it is greater than 1, objects of each type will be hashed across up to 10^(depth - 1) directories. Except for testing purposes, this parameter should be 2 or greater.
  • A boolean flag indicating whether or not HTTP connections should be supported. HTTP support is still somewhat experimental, so you may choose to turn it off if you do not need it.
  • An integer indicating how often (in seconds) idle objects in the server's in-memory cache should be purged.
The small program below (Server.java) starts a CORK server:

     1  import edu.vt.cs.collab.cork.impl.inet.ServerImpl;
     2
     3  /**
     4   * Simple CORK server, with little error handling. Should be
     5   * executed with port number as an argument.
     6   */
     7  public class Server {
     8
     9      public Server(int port) {
    10          try {
    11              ServerImpl server = new ServerImpl(
    12                  port,   // port the server listens on
    13                  "DATA", // directory the server stores object data in
    14                  2,      // Depth of storage directories
    15                  true,   // support http connections
    16                  10 * 60);  // purge idle objects every 10 minutes
    17          }
    18          catch(Exception e) {
    19              System.err.println("Server startup failed: ");
    20              e.printStackTrace();
    21          }
    22      }
    23
    24      public static void main(String[] args) {
    25          int port = Integer.parseInt(args[0]);
    26          Server s = new Server(port);
    27      }
    28
    29
    30  }
Executing:
csh> java Server 1500
would start a CORK server that listened on port 1500.

Note that it is not necessary to inform the server of the kinds of objects that it will be replicating. It is, however, necessary that the class definitions (.class files) be available in the server's classpath on the first request to retrieve an object of a given class.
The server shown in Server.java includes no authentication support, so users could log on using any user id and password. To add authentication, an appropriate Authenticator class could be constructed and set using ServerImpl's setAuthenticator method.


/public/chci/howto/cork/server.html Login | Web Editor | Full Editor
Last modified 5/22/03 3:15 PM by isenhour (history)
Site contents