/*
 * 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;

    // parameter setting have been removed to client side
	String algorithm;
	int bufferSize;
	long modifyPeriod;   // aux size modification period	
    boolean isFixFileSize;
    
	
	/**
	 * put your documentation comment here
	 * @param 
	 */
	public void onCreation (Object obj) 
	{
		try
		{
            Object[] init = (Object[])obj;            
            algorithm = (String)init[0];
            bufferSize = ((Integer)init[1]).intValue();
            modifyPeriod = ((Long)init[2]).longValue();
            isFixFileSize = ((Boolean)init[3]).booleanValue();
            
			bufferControl = new BufferControl(algorithm, bufferSize, modifyPeriod, isFixFileSize);
		}
		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;
	}
}



