key0-96/
key0-96/doc/key/
key0-96/doc/key/credits/
key0-96/doc/key/developers/
key0-96/doc/key/developers/resources/
key0-96/setup/caves/
key0-96/setup/help/
key0-96/setup/ruins/
key0-96/src/
key0-96/src/commands/
key0-96/src/events/
key0-96/src/hack/
key0-96/src/sql/
key0-96/src/swing/
key0-96/src/talker/forest/
key0-96/src/talker/objects/
key0-96/src/terminals/
/**
  *  Command: Gc
  *
  *
 */

package key.commands;
import key.*;
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.io.IOException;

public class Gc extends Command
{
	public Gc()
	{
		setKey( "gc" );
		usage = "";
	}

	public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException
	{
		Key key = Key.instance();
		Runtime rt = Runtime.getRuntime();
		LatentCache lc = key.getLatencyCache();
		
		if( !lc.isAlive() && key.isRunning() )
		{
			ic.send( "The latency cache has died.  No further processing." );
			return;
		}
		
		if( p.isBeyond() )
		{
			ic.send( "Compressing registry." );
			Registry.instance.compress();
			
			//ic.send( "Interupting latency cache." );
			//lc.interrupt();
			Thread.yield();
			
			ic.send( "Running garbage collection." );
			rt.gc();
			ic.send( "Running finalisation." );
			rt.runFinalization();
			
			try
			{
				Thread.sleep( 250 );
			}
			catch( Exception e )
			{
			}
		}
		
		ic.send( Long.toString( rt.totalMemory() ) + " bytes allocated, "
			+ Long.toString( rt.freeMemory() ) + " bytes of that remaining" );
		System.err.println( Long.toString( rt.totalMemory() ) + " bytes allocated, "
			+ Long.toString( rt.freeMemory() ) + " bytes of that remaining" );
	}
}