/**
* @Package: com.scap.servers.scapserver.ejb
* @CreateDate Apr 15, 2005
* @Creator eha
*
* TODO Add more info
*/
package com.scap.servers.scapserver.ejb;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Logger;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.TimedObject;
import javax.ejb.Timer;
/**
* XDoclet-based session bean. The class must be declared
* public according to the EJB specification.
*
* To generate the EJB related files to this EJB:
* - Add Standard EJB module to XDoclet project properties
* - Customize XDoclet configuration for your appserver
* - Run XDoclet
*
* Below are the xdoclet-related tags needed for this EJB.
*
* @ejb.bean name="TimerTest"
* display-name="Name for TimerTest"
* description="Description for TimerTest"
* jndi-name="ejb/TimerTest"
* type="Stateless"
* view-type="both"
*
* @ejb.transaction type = "NotSupported"
*/
public class TimerTestBean implements SessionBean, TimedObject
{
/** The session context */
private SessionContext m_context;
private Logger m_log = Logger.getLogger(TimerTestBean.class.getName());
/**
*
*/
public TimerTestBean()
{
super();
// TODO Auto-generated constructor stub
}
/**
* Set the associated session context. The container calls this method
* after the instance creation.
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable.
*
* This method is called with no transaction context.
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void setSessionContext(SessionContext newContext) throws EJBException
{
m_context = newContext;
}
/* (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
{
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException
{
// TODO Auto-generated method stub
}
/**
* An ejbCreate method as required by the EJB specification.
*
* The container calls the instance?s ejbCreate
method whose
* signature matches the signature of the create
method invoked
* by the client. The input parameters sent from the client are passed to
* the ejbCreate
method. Each session bean class must have at
* least one ejbCreate
method. The number and signatures
* of a session bean?s create
methods are specific to each
* session bean class.
*
* @throws CreateException Thrown if method fails due to system-level error.
*
* @ejb.create-method
*
*/
public void ejbCreate() throws CreateException
{
// TODO Add ejbCreate method implementation
}
private void startTimer(Serializable info)
{
m_log.info("Starting timer. Info="+info);
m_context.getTimerService().createTimer(10000,info);
}
/**
* @ejb.interface-method
* @ejb.transaction type = "Required"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void startTimerInTxRequired() throws EJBException
{
startTimer("Required");
}
/**
* @ejb.interface-method
* @ejb.transaction type = "RequiresNew"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void startTimerInTxRequiresNew() throws EJBException
{
startTimer("Required");
}
/**
* @ejb.interface-method
* @ejb.transaction type = "Never"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void startTimerInTxNever() throws EJBException
{
startTimer("Never");
}
/**
* @ejb.interface-method
* @ejb.transaction type = "NotSupported"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void startTimerInTxNotSupported() throws EJBException
{
startTimer("NotSupported");
}
private void cancelTimers()
{
Collection timers = m_context.getTimerService().getTimers();
for (Iterator it = timers.iterator();it.hasNext();)
{
Timer t = (Timer)it.next();
m_log.info("Cancelling timer"+t+" "+t.getInfo());
t.cancel();
m_log.info("Timer is now"+t);
}
}
/**
* @ejb.interface-method
*/
public int listAllTimers()
{
Collection timers = m_context.getTimerService().getTimers();
String s="Timers:";
for (Iterator it = timers.iterator();it.hasNext();)
{
Timer t = (Timer)it.next();
s = s +t.toString() + " ";
try
{
s += t.getInfo();
}
catch (Exception e)
{
}
s+="\n";
}
m_log.info(s);
return timers.size();
}
/**
* @ejb.interface-method
* @ejb.transaction type = "Required"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void cancelTimerInTxRequired() throws EJBException
{
cancelTimers();
}
/**
* @ejb.interface-method
* @ejb.transaction type = "RequiresNew"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void cancelTimerInTxRequiresNew() throws EJBException
{
cancelTimers();
}
/**
* @ejb.interface-method
* @ejb.transaction type = "Never"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void cancelTimerInTxNever() throws EJBException
{
cancelTimers();
}
/**
* @ejb.interface-method
* @ejb.transaction type = "NotSupported"
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void cancelTimerInTxNotSupported() throws EJBException
{
cancelTimers();
}
/* (non-Javadoc)
* @see javax.ejb.TimedObject#ejbTimeout(javax.ejb.Timer)
*/
public void ejbTimeout(Timer timer)
{
m_log.info("ejbTimeout:"+timer);
}
}