FileDocCategorySizeDatePackage
ServerCommunicatorAdmin.javaAPI DocJava SE 5 API5456Fri Aug 26 14:55:00 BST 2005com.sun.jmx.remote.internal

ServerCommunicatorAdmin

public abstract class ServerCommunicatorAdmin extends Object

Fields Summary
private long
timestamp
private final int[]
lock
private int
currentJobs
private long
timeout
private boolean
terminated
private static final ClassLogger
logger
private static final ClassLogger
timelogger
Constructors Summary
public ServerCommunicatorAdmin(long timeout)

	if (logger.traceOn()) {
	    logger.trace("Constructor",
			 "Creates a new ServerCommunicatorAdmin object "+
			 "with the timeout "+timeout);
	}

	this.timeout = timeout;

	timestamp = 0;
        if (timeout < Long.MAX_VALUE) {
            Runnable timeoutTask = new Timeout();
            final Thread t = new Thread(timeoutTask);
            t.setName("JMX server connection timeout " + t.getId());
            // If you change this name you will need to change a unit test
	    // (NoServerTimeoutTest)
            t.setDaemon(true);
            t.start();
        }
    
Methods Summary
protected abstract voiddoStop()
Called by this class to tell an implementation to do stop.

private voidlogtime(java.lang.String desc, long time)

	timelogger.trace("synchro",desc+time);
    
public booleanreqIncoming()
Tells that a new request message is received. A caller of this method should always call the method rspOutgoing to inform that a response is sent out for the received request.

return
the value of the termination flag:
    true if the connection is already being terminated,
    false otherwise.

	if (logger.traceOn()) {
	    logger.trace("reqIncoming", "Receive a new request.");
	}

	synchronized(lock) {
	    if (terminated) {
		logger.warning("reqIncoming",
			       "The server has decided to close " +
			       "this client connection.");
	    }
	    ++currentJobs;

	    return terminated;
	}
    
public booleanrspOutgoing()
Tells that a response is sent out for a received request.

return
the value of the termination flag:
    true if the connection is already being terminated,
    false otherwise.

	if (logger.traceOn()) {
	    logger.trace("reqIncoming", "Finish a request.");
	}

	synchronized(lock) {
	    if (--currentJobs == 0) {
		timestamp = System.currentTimeMillis();
		logtime("Admin: Timestamp=",timestamp);
		// tells the adminor to restart waiting with timeout
		lock.notify();
	    }
	    return terminated;
	}
    
public voidterminate()
Terminates this object. Called only by outside, so do not need to call doStop

        if (logger.traceOn()) {
	    logger.trace("terminate", 
			 "terminate the ServerCommunicatorAdmin object.");
	}

	synchronized(lock) {
	    if (terminated) {
		return;
	    }

	    terminated = true;

	    // tell Timeout to terminate
	    lock.notify();
	}