/*
 * put your module comment here
 * formatted with JxBeauty (c) johann.langhofer@nextra.at
 *
 * formatted with JxBeauty (c) johann.langhofer@nextra.at
 */


package  project;

import  com.ibm.aglet.*;
import  com.ibm.aglet.event.*;
import  java.net.URL;
import  java.util.*;


/**
 * put your documentation comment here
 */
public class Server extends Aglet 
{
	BufferControl bufferControl;
	String algorithm = "PureLRU";
	int bufferSize = 100000;
	long modifyPeriod = 5;   // aux size modification period
	int fileSizeBound = 0; //0 for fix size
	
	/**
	 * put your documentation comment here
	 * @param o
	 */
	public void onCreation (Object o) 
	{
		try
		{
			bufferControl = new BufferControl(algorithm, bufferSize, modifyPeriod, fileSizeBound);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public void onDisposing()
	{
		bufferControl.printHitStatic();
	}

	public boolean handleMessage(Message msg) 
	{
		if(msg.sameKind("request"))
		{
			try
			{
				bufferControl.requestFile((String)msg.getArg());
				return true;
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		return false;
	}
}



