The Artima Developer Community
Sponsored Link

Observing JavaSpace-Based Systems, Part II
How to Log and Analyze a Space-Based Distributed System
by Philip Bishop & Nigel Warren
October 14, 2002

<<  Page 5 of 6  >>

Advertisement

Remote Logging Proxy

Earlier we looked at the LocalLoggingProxy class, which implemented our LoggingSpace interface and simply wrote the logging information to the local VM console. Much of the code in the LocalLoggingProxy is the same as we'll need for our logging service, except that the call to logOperation() will delegate to the SpaceLogger rather than writing to disk. For this reason, we should define an abstract class that both the LocalLoggingProxy and LoggingServiceProxy can extend:

public abstract class AbstractLoggingProxy
        implements LoggingSpace, Externalizable {

    private JavaSpace _delegateSpace;

    //readExternal() same as in original code
    //writeExternal() same as in original code

    public abstract
            void logOperation(SpaceOperation op);

    public Lease write(Entry entry,
                       Transaction txn, long lease)
            throws TransactionException,
            RemoteException {
        logOperation(
                new SpaceOperation("write", entry, txn, lease));
        return _delegateSpace.write(entry, txn, lease);
    }
    //All the other JavaSpaces methods
}    

The LocalLoggingProxy would then simply look as follows, as its superclass handles finding the delegate space and forwarding the calls:

public class LocalLoggingProxy extends AbstractLoggingProxy{

    public void logOperation(SpaceOperation op) {
        System.out.println(op.toString());
    }
} 

Our new LoggingServiceProxy looks like this:

public class LoggingServiceProxy extends AbstractLoggingProxy
        implements Serializable {
    private SpaceLogger _logger;

    public void readExternal(ObjectInput in)
            throws IOException, ClassNotFoundException {
        //Will find the JavaSpace
        super.readExternal(in);
        try {
            //Now locate the logging service's proxy
            _logger =
                    ServiceLocator.getService(SpaceLogger.class);
        }
        catch (Exception exp) {
            throw new IOException(
                    "Can't find logging service " + exp.toString());
        }
    }

    public void writeExternal(ObjectOutput out)
            throws IOException {
        super.writeExternal();
    }

    public void logOperation(SpaceOperation op)
            throws RemoteException {
        _logger.logOperation(op);
    }
}

We use the same technique of locating the delegate services in the LoggingServiceProxy class (i.e. when the proxy is deserialized) as we did in the LocalLoggingProxy in Part I. This technique allows us register the proxy without having to locate and bind to the delegate services at that time.

In both logging models, we have used this late binding technique to find the delegate services at the point the proxy is deserialized in the client. As an alternative approach, you could have the RegisterProxy class locate the required service or services and initialize the proxies with them. This approach has the advantage that a proxy will only be registered if the delegate services can be found. However, if any delegate service stops and restarts after the proxy has been registered, the remote reference (to the delegate service(s)) would become invalid, unless of course, they are activatable services with persistent remote references.

The final stage is to write the class that registers the logging service.

Server and Client

In Part I, we saw how to register the LocalLoggingProxy to the Jini lookup service. As the code for registering the LoggingServiceProxy is identical, except the proxy's class and name attribute, we won't repeat it here.

The client code to use the logging service also follows the same steps as the LocalLoggingProxy did in part 1, so again we wont repeat that code here.

<<  Page 5 of 6  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us