[Jboss-cvs] JBossAS SVN: r56182 - trunk/ejb3/src/main/org/jboss/ejb3/timerservice
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 23 11:54:55 EDT 2006
Author: wolfc
Date: 2006-08-23 11:54:49 -0400 (Wed, 23 Aug 2006)
New Revision: 56182
Removed:
trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/timerservice/package.html
Log:
Deleted: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java 2006-08-23 15:26:18 UTC (rev 56181)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/TimerServiceFactory.java 2006-08-23 15:54:49 UTC (rev 56182)
@@ -1,267 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.timerservice;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.Properties;
-
-import javax.ejb.TimerService;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.TransactionManager;
-
-import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionManagerService;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerFactory;
-import org.quartz.impl.StdSchedulerFactory;
-import org.quartz.utils.DBConnectionManager;
-import org.quartz.utils.JNDIConnectionProvider;
-
-/**
- * Creates timer service objects for use in EJB3 containers. For this
- * two methods are provided: createTimerService and removeTimerService.
- *
- * The factory can be started and stopped within both an embedded and full stack.
- *
- * For now only one scheduler is supported. Each bean container has its own
- * job and trigger group within Quartz.
- *
- * @author <a href="mailto:carlo at nerdnet.nl">Carlo de Wolf</a>
- * @version $Revision$
- */
-public class TimerServiceFactory
-{
- @SuppressWarnings("unused")
- private static final Logger log = Logger.getLogger(TimerServiceFactory.class);
-
- private TransactionManager tm;
-
- private static Scheduler scheduler;
-
- private Properties properties;
-
- /**
- * Contains the sql statements to create the database schema.
- */
- private Properties sqlProperties;
-
- private void createSchema()
- {
- try
- {
- tm.begin();
- try
- {
- Connection conn = getConnection();
- try
- {
- boolean success = execute(conn, "CREATE_TABLE_JOB_DETAILS");
- if(success)
- {
- execute(conn, "CREATE_TABLE_JOB_LISTENERS");
- execute(conn, "CREATE_TABLE_TRIGGERS");
- execute(conn, "CREATE_TABLE_SIMPLE_TRIGGERS");
- execute(conn, "CREATE_TABLE_CRON_TRIGGERS");
- execute(conn, "CREATE_TABLE_BLOB_TRIGGERS");
- execute(conn, "CREATE_TABLE_TRIGGER_LISTENERS");
- execute(conn, "CREATE_TABLE_CALENDARS");
- execute(conn, "CREATE_TABLE_PAUSED_TRIGGER_GRPS");
- execute(conn, "CREATE_TABLE_FIRED_TRIGGERS");
- execute(conn, "CREATE_TABLE_SCHEDULER_STATE");
- execute(conn, "CREATE_TABLE_LOCKS");
-
- execute(conn, "INSERT_TRIGGER_ACCESS");
- execute(conn, "INSERT_JOB_ACCESS");
- execute(conn, "INSERT_CALENDAR_ACCESS");
- execute(conn, "INSERT_STATE_ACCESS");
- execute(conn, "INSERT_MISFIRE_ACCESS");
- }
- }
- finally
- {
- conn.close();
- }
- tm.commit();
- }
- catch(SQLException e)
- {
- throw new RuntimeException(e);
- }
- catch (RollbackException e)
- {
- throw new RuntimeException(e);
- }
- catch (HeuristicMixedException e)
- {
- throw new RuntimeException(e);
- }
- catch (HeuristicRollbackException e)
- {
- throw new RuntimeException(e);
- }
- finally
- {
- if(tm.getStatus() == Status.STATUS_ACTIVE)
- tm.rollback();
- }
- }
- catch(SystemException e)
- {
- throw new RuntimeException(e);
- }
- catch (NotSupportedException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Create a TimerService for use in a bean container.
- *
- * @param objectName the name of the bean container
- * @param invoker the invoker to call on timeouts
- * @return an EJB TimerService
- */
- public static TimerService createTimerService(ObjectName objectName, TimedObjectInvoker invoker)
- {
- Scheduler scheduler = getScheduler();
- if (scheduler == null) return null;
-
- return new TimerServiceImpl(scheduler, objectName, invoker);
- }
-
- private boolean execute(Connection conn, String stmtName) throws SQLException
- {
- String sql = sqlProperties.getProperty(stmtName);
- if(sql == null)
- throw new IllegalStateException("No sql set for '" + stmtName + "'");
-
- PreparedStatement stmt = conn.prepareStatement(sql);
- try
- {
- stmt.execute();
- return true;
- }
- catch(SQLException e)
- {
- log.warn("sql failed: " + sql);
- if(log.isDebugEnabled())
- log.debug("sql failed: " + sql, e);
- return false;
- }
- finally
- {
- stmt.close();
- }
- }
-
- private Connection getConnection() throws SQLException
- {
- return DBConnectionManager.getInstance().getConnection("myDS");
- }
-
- /**
- * @return the scheduler for package use
- */
- protected static Scheduler getScheduler()
- {
- if(scheduler == null)
- {
- return null;
- //throw new IllegalStateException("TimerServiceFactory hasn't been started yet");
- }
-
- return scheduler;
- }
-
- public static void removeTimerService(TimerService aTimerService)
- {
- TimerServiceImpl timerService = (TimerServiceImpl) aTimerService;
- timerService.shutdown();
- }
-
- public void setDataSource(String jndiName)
- {
- JNDIConnectionProvider connectionProvider = new JNDIConnectionProvider(jndiName, false);
- // FIXME: remove hardcoding
- DBConnectionManager.getInstance().addConnectionProvider("myDS", connectionProvider);
- }
-
- public void setProperties(final Properties props)
- {
-// if(scheduler != null)
-// throw new IllegalStateException("already started");
-
- // TODO: precondition the prop
- properties = props;
- }
-
- public void setSqlProperties(Properties props)
- {
- this.sqlProperties = props;
- }
-
- public synchronized void start() throws Exception
- {
- if(scheduler != null)
- throw new IllegalStateException("already started");
-
- log.debug("properties = " + properties);
-
- InitialContext ctx = new InitialContext();
- tm = (TransactionManager) ctx.lookup(TransactionManagerService.JNDI_NAME);
-
- createSchema();
-
- // TODO: bind in JNDI, or is this done by the JMX bean?
- SchedulerFactory factory;
- if(properties == null)
- factory = new StdSchedulerFactory();
- else
- factory = new StdSchedulerFactory(properties);
- scheduler = factory.getScheduler();
- // TODO: really start right away?
- scheduler.start();
- }
-
- public synchronized void stop() throws Exception
- {
- if(scheduler == null)
- throw new IllegalStateException("already stopped");
-
- // TODO: unbind from JNDI
-
- // TODO: standby or shutdown?
- scheduler.shutdown();
-
- scheduler = null;
- }
-}
Deleted: trunk/ejb3/src/main/org/jboss/ejb3/timerservice/package.html
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/timerservice/package.html 2006-08-23 15:26:18 UTC (rev 56181)
+++ trunk/ejb3/src/main/org/jboss/ejb3/timerservice/package.html 2006-08-23 15:54:49 UTC (rev 56182)
@@ -1,17 +0,0 @@
-<head>
- <body>
- This package provides the EJB Timer Service to the EJB3 stack.
- <p/>
- It replaces the org.jboss.ejb.txtimer package.
- <p/>
- The Jboss EJB3 Timer Service package depends on:
- <ul>
- <li>EJB3 API</li>
- <li>Quartz</li>
- <li>JTA</li>
- </ul>
- <p/>
- Note that almost all exceptions are caught and rethrown as EJBExceptions, thus
- making sure that no Quartz API is exposed either compile time or run time.
- </body>
-</head>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list