Jai,
My Timer bean code is
|
| /**
| * Timer bean used to periodically search to see if any pager forward requests have
been entered.
| *
| * @jboss.container-configuration name="Singleton oncall Standard Stateless
SessionBean"
| *
| *
| */
|
|
|
| @Stateless(mappedName="ejb/OnCallTimerBean")
| @Remote(OnCallTimer.class)
| @Local(OnCallTimer.class)
| public class OnCallTimerBean implements OnCallTimer {
|
|
|
| /**
| * use for logging
| */
| Log log = LogFactory.getLog(this.getClass());
|
| /**
| * reference to the timer handle
| */
|
| private TimerHandle timerHandle = null;
|
| /**
| * Poll records after following interval.
| */
| private static int POLLING_TIME = 60000;
|
| /**
| * status flag to determine transaction state
| * set this flag to disable timer call
| */
| private static boolean processFlag = false;
|
|
| private OnCallService oncallService = null;
|
| @Resource
| private SessionContext sessionCtx;
| public void startTimer() {
|
| System.out.print ("Inside startTimer ");
| if (log.isInfoEnabled()) {
| log.info("startTimer Service ");
| }
|
| try {
| // Create timerService instance
| TimerService timerService = sessionCtx.getTimerService();
|
| Collection timers = timerService.getTimers();
| Iterator it = timers.iterator();
| while (it.hasNext()) {
| Timer aTimer = (Timer) it.next();
| if (log.isInfoEnabled()) {
| log.info("checking timer with info " + aTimer.getInfo());
| }
|
| if ((aTimer.getInfo() != null)
| && ((aTimer.getInfo().equals(this.getClass().getName())))) {
| aTimer.cancel();
| if (log.isInfoEnabled()) {
| log.info("Successfully Cancelled "
| + this.getClass().getName());
| }
|
| }
| }
|
| //at this point all timers should be canceled.
| //now we can create our own timer.
|
| Timer timer = timerService.createTimer(0, POLLING_TIME, this.getClass()
| .getName());
| timerHandle = timer.getHandle();
| } catch (Exception e) {
| log.error("An exception occurred while creating the Oncall Timer.",
| e);
| }
| return;
| }
|
|
|
| public void endTimedService() throws EJBException {
| System.out.print ("Inside endTimedService ");
| if (log.isInfoEnabled()) {
| log.info("endTimedService ");
| }
| try {
| TimerService timerService = sessionCtx.getTimerService();
| Collection timers = timerService.getTimers();
| Iterator it = timers.iterator();
| while (it.hasNext()) {
| Timer myTimer = (Timer) it.next();
| if ((myTimer.getInfo().equals(this.getClass().getName()))) {
| myTimer.cancel();
| if (log.isInfoEnabled()) {
| log.info("Successfully Cancelled "
| + this.getClass().getName());
| }
| }
| }
| } catch (Exception e) {
| log.error("Exception after cancelling timer!", e);
| }
| return;
| }
|
|
|
| @Timeout
| public void timeout(Timer timer){
|
| System.out.print ("initiateServiceBean ");
| if (log.isDebugEnabled()) {
| StringBuffer debug = new StringBuffer();
| debug
| .append("OncallTimedService: Searching for requests ready to
process.");
| log.debug(debug.toString());
| }
|
| if (!processFlag){
| try {
|
| // set the process flag
| processFlag = true;
|
| // Call getCalendar method of Oncall service object
| oncallService.getCalendar();
| //reset the process flag
| processFlag = false;
| }catch (Throwable t) {
| if (log.isWarnEnabled()) {
| log
| .warn(
| "An exception occurred while searching for the pager forwards.",
| t);
| }
|
| processFlag = false;
|
| throw new EJBException(t.toString());
| }
|
|
| }
| return;
| }
|
|
| }
Also I added following entry in the
C:\jboss-4.2.1.GA\server\tools1\confstandardjboss.xml
<container-configuration>
| <container-name>Singleton oncall Standard Stateless
SessionBean</container-name>
| <call-logging>false</call-logging>
|
<invoker-proxy-binding-name>stateless-unified-invoker</invoker-proxy-binding-name>
| <container-interceptors>
|
<interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>
| <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
|
<interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor>
| <!-- CMT -->
| <interceptor
transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMT</interceptor>
| <interceptor
transaction="Container">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor>
| <interceptor
transaction="Container">org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor</interceptor>
| <!-- BMT -->
| <interceptor
transaction="Bean">org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor</interceptor>
| <interceptor
transaction="Bean">org.jboss.ejb.plugins.TxInterceptorBMT</interceptor>
| <interceptor
transaction="Bean">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor>
|
<interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptor</interceptor>
| </container-interceptors>
|
<instance-pool>org.jboss.ejb.plugins.StatelessSessionInstancePool</instance-pool>
| <instance-cache></instance-cache>
| <persistence-manager></persistence-manager>
| <container-pool-conf>
| <MaximumSize>1</MaximumSize>
| </container-pool-conf>
| </container-configuration>
Other than this i did not do anything.
Thanks
Pramkum.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215042#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...