What you need:

  • ejbspaces package
  • additional jars (jini-core.jar, jini-ext.jar, j2ee.jar)
  • ejb app server
    optional:
  • relational database (for persistant space)

    Server:

    Install

  • unzip the package into any directory.
  • Get the additional jars

    Configuration

  • Additional jars in classpath of server
  • create ear or use ejbspaces.jar
  • Will need to add entries jar to classpath

    Deploy

  • follow server directions for deployment
  • make sure ejbspaces.jar, additional jars and entries jar are in classpath of server

    Client side:

    Configuration

  • client classpath will need: ejbspaces.jar with client stubs or a generated cleint jar with stubs, additional jars, entries jar, perhaps j2ee.jar

    Creating Entries

  • Add entries to entries jar, must be in classpath of client and server

    Accessing the space

  • You should set the initialcontext name and url with system properties (i.e start the server with "-D=" for each property)
  • you should access the ejbspace just like you would any other EJB (through JNDI lookup) this should be transparent by using the provided space accessor class (com.stabba.ejbspace.space.SpaceFactory). Here's how to access it:

        JavaSpace space = SpaceFactory.getSpace(SpaceFactory.REMOTE); //get remote (from app server space)

    For testing,etc you can create a local space with no remote calls:

        JavaSpace space = SpaceFactory.getSpace(SpaceFactory.LOCAL); //get local space

    The transaction service work the same way, you might want to return a handle the transaction with code like this (see the specification for the API):

     private Transaction getTransaction(){
        Transaction txn = null;
        try {
            TransactionManager mgr = TransactionManagerFactory.getManager(TransactionManagerFactory.REMOTE);
            Transaction.Created trc = TransactionFactory.create(mgr, 10*60*1000);//timeout after
            txn = trc.transaction;
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return txn;
     }

    Persistance:

  • You will need to create the tables, here is basic DDL script - you may need to modify it to suit your vendor.

    CREATE TABLE ejb_space
        (id NUMBER PRIMARY KEY, name VARCHAR(25))
    CREATE TABLE entry
        (id NUMBER PRIMARY KEY, space_id NUMBER, entry LONG)

  • You should create a DataSource through your app server. This is also vendor specific. You can name the dataSource whatever you want (in jndi) (the default is "java:/XAOracleDS")
  • You need to supply the data source JNDI name and database username and password in ejb-jar.xml as well (default for username/password is "ejbspaces/ejbspaces". The tags you need to set for persistance are:
        DATA_SOURCE_NAME
        DATA_SOURCE_USERNAME
        DATA_SOURCE_PASSWORD
  • Another tag turns persistance on and off (default is "false"):     PERSIST=true

    Developers:

    Getting the source:
    Compiling: