/*
 * Created on Apr 18, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.dragonsoft.tryapp.ejb.session;

import java.rmi.RemoteException;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

import com.dragonsoft.tryapp.common.SubmissionObj;
import com.dragonsoft.tryapp.ejb.session.utils.ExecutionManager;

import fireTester.interfaces.SubmissionTest;
import fireTester.messages.TestUnitResults;
import fireTester.messages.TesterException;

/**
 * @ejb.bean name="ProcessMonitor"
 *           display-name="Name for ProcessMonitor"
 *           description="Description for ProcessMonitor"
 *           jndi-name="ejb/ProcessMonitor"
 *           type="Stateful"
 *           view-type="remote"
 */
public class ProcessMonitorBean implements SessionBean {

	private ExecutionManager manager;

	/**
	 * 
	 */
	public ProcessMonitorBean() {
		super();
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
	 */
	public void setSessionContext(SessionContext ctx)
		throws EJBException,
		RemoteException {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbRemove()
	 */
	public void ejbRemove() throws EJBException, RemoteException {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbActivate()
	 */
	public void ejbActivate() throws EJBException, RemoteException {
		this.manager = ExecutionManager.getSingleton();
	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbPassivate()
	 */
	public void ejbPassivate() throws EJBException, RemoteException {
		
	}

	/**
	 * Adds a Test Process to the system.
	 * Business method
	 * @ejb.interface-method  view-type = "remote"
	 */
	public boolean addProcess(
		SubmissionObj submissionID,
		SubmissionTest tests) {
		System.out.println("About to submit");
		this.manager.addSubmission(submissionID,tests);
		return true;
	}
	
	/**
	 * Poll for results to a SubmissionID
	 * Business method
	 * @ejb.interface-method  view-type = "both"
	 */
	public TestUnitResults[] getResults(String id)throws TesterException{
		TestUnitResults[] rtVal = this.manager.getResults(id);
		return rtVal;
	}
	/**
	 * Create method
	 * @ejb.create-method  view-type = "remote"
	 */
	public void ejbCreate() throws javax.ejb.CreateException {
		this.manager = ExecutionManager.getSingleton();
	}
}
