ConnectionStatistics.java

key0-96/src/core/ConnectionStatistics.java · 1.4 KB

From the archive key0-96.tar.bz2

Download the archive   « Back to the archive contents

package key;

import key.primitive.*;

import java.io.*;

/**
  *  A statistics class that keeps idle time
 */
public final class ConnectionStatistics extends Atom
{
	private static final long serialVersionUID = 4197321215561299181L;
	
	public static final AtomicElement[] ELEMENTS =
	{
			//  String getName();
		AtomicElement.construct( ConnectionStatistics.class, DateTime.class, "lastUnIdle",
			AtomicElement.PUBLIC_FIELD,
			"the time the last command was executed" ),
		AtomicElement.construct( ConnectionStatistics.class, Duration.class, "idleTime",
			AtomicElement.PUBLIC_ACCESSORS | AtomicElement.READ_ONLY,
			"the amount of time this connection has been idle" )
	};
	
	public static final AtomicStructure STRUCTURE = new AtomicStructure( Atom.STRUCTURE, ELEMENTS );
	
	/**
	  *  The time the last command was executed
	 */
	public DateTime lastUnIdle;
	
	public ConnectionStatistics()
	{
		unIdle();
	}
	
	public AtomicStructure getDeclaredStructure()
	{
		return( STRUCTURE );
	}

	public void loaded()
	{
		super.loaded();
		unIdle();
	}
	
	/**
	  *  Unidles the connection to the current time
	 */
	public void unIdle()
	{
		lastUnIdle = new DateTime();
	}
	
	public final Duration getIdleTime()
	{
		return( lastUnIdle.difference( new DateTime() ) );
	}
	
	public final Duration getIdleTime( DateTime currentTime )
	{
		return( lastUnIdle.difference( currentTime ) );
	}
}

Site Stats

Snippets: 1791
Codebases: 571