The Artima Developer Community
Sponsored Link

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

<<  Page 3 of 6  >>

Advertisement

A Logging Information Model

We have two candidate object models for our logging information. The first is a class-based model illustrated in Figure 2. A quick view of the JavaSpace interface can be mapped to an inheritance graph representing the various operations that we might record in the logging system.


Figure 2. A Class Hierarchy for Logging JavaSpace Operations.

As you can see from the class hierarchy, there is an operation class for every method call in the JavaSpace interface and others to deal with the more general or abstract information.

This model has the general advantage that only the information that applies to a particular operation type will be stored and recorded in the object representing that operation. It also has the standard property of extensibility and flexibility normally associated with type- based inheritance systems. However, the model does add complexity and raise the class count dramatically.

The other alternative holds all the method information and parameters in one class using null information for fields not used for a particular operation. In this case, we need to add a field to represent the operation being called instead of using the Java type system to encode the operation. Here is the Java code for a simple compound SpaceOperation class.

import java.io.Serializable;
import java.net.InetAddress;

import net.jini.core.entry.Entry;
import net.jini.core.lease.Lease;
import net.jini.core.transaction.Transaction;

public class SpaceOperation
        implements Serializable {
    private long _timeStamp;
    private String _host;
    private String _thread;
    private String _method;
    private String _entry;
    private String _txn;
    private long _timeVal;
    private static String _hostCache;

    SpaceOperation(String method, Entry entry,
                   Transaction txn, long timeVal) {
        _timeStamp = System.currentTimeMillis();
        _host = getHostDetails();
        _thread = Thread.currentThread().getName();
        _method = method;
        if (entry != null) {
            _entry = entry.getClass().getName();
        }
        if (txn != null) {
            _txn = txn.toString();
        }
        _timeVal = timeVal;
    }

    private String getHostDetails() {
        if (_hostCache == null) {
            try {
                InetAddress host =
                        InetAddress.getLocalHost();
                _hostCache = host.toString();
            }
            catch (java.net.UnknownHostException exp) {
                _hostCache = "No Host Details";
            }
        }
        return _hostCache;
    }

    private static final char comma = ',';
    private static final int BUF_SIZE = 128;

    public String toString() {
        StringBuffer buf = new StringBuffer(BUF_SIZE);
        buf.append(new java.util.Date(_timeStamp));
        buf.append(comma);
        buf.append(_host);
        buf.append(comma);
        buf.append(_thread);
        buf.append(comma);
        buf.append(_method);
        buf.append(comma);
        buf.append(_entry);
        buf.append(comma);
        buf.append(_txn);
        buf.append(comma);
        buf.append(_timeVal);
        return buf.toString();
    }
}

Every time a call is made on the JavaSpaces API in a logging proxy, we can create a new instance of the SpaceOperation class to log the operation type and its parameters. The class also overrides the toString() method of the Object class to encode the information in a comma-separated format, so that we can easily parse it with other software tools.

This single-class model seems adequate for our purposes while still being simple and lightweight. Now that we can record and format our logging information, we can look at our first logging proxy implementation.

<<  Page 3 of 6  >>


Sponsored Links



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