[jboss-cvs] JBossAS SVN: r63698 - in branches/JBoss_4_0_0_CP: server/src/main/org/jboss/ejb/txtimer and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 27 14:33:30 EDT 2007
Author: scott.stark at jboss.org
Date: 2007-06-27 14:33:30 -0400 (Wed, 27 Jun 2007)
New Revision: 63698
Added:
branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePlugin.java
branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java
branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/OracleDatabasePersistencePlugin.java
Modified:
branches/JBoss_4_0_0_CP/server/src/etc/deploy/ejb-deployer.xml
branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java
branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/NoopPersistencePolicy.java
branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/PersistencePolicy.java
branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java
branches/JBoss_4_0_0_CP/testsuite/.classpath
branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/txtimer/test/PersistenceTestCase.java
Log:
ASPATCH-203, The timers to be restored are read at the DatabasePersistencePolicy startup prior to any new timers being created to avoid seeing new timers created before server startup completes.
Modified: branches/JBoss_4_0_0_CP/server/src/etc/deploy/ejb-deployer.xml
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/etc/deploy/ejb-deployer.xml 2007-06-27 18:31:52 UTC (rev 63697)
+++ branches/JBoss_4_0_0_CP/server/src/etc/deploy/ejb-deployer.xml 2007-06-27 18:33:30 UTC (rev 63698)
@@ -5,89 +5,65 @@
-->
<server>
- <!-- ==================================================================== -->
- <!-- J2EE Timer Service -->
- <!-- ==================================================================== -->
+ <!-- ==================================================================== -->
+ <!-- J2EE Timer Service -->
+ <!-- ==================================================================== -->
- <!-- An EJB Timer Service that is Tx aware -->
- <mbean code="org.jboss.ejb.txtimer.EJBTimerServiceImpl"
- name="jboss.ejb:service=EJBTimerService">
- <attribute name="RetryPolicy">jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay</attribute>
- <attribute name="PersistencePolicy">jboss.ejb:service=EJBTimerService,persistencePolicy=database</attribute>
- <attribute name="TimerIdGeneratorClassName">org.jboss.ejb.txtimer.BigIntegerTimerIdGenerator</attribute>
- <attribute name="TimedObjectInvokerClassName">org.jboss.ejb.txtimer.TimedObjectInvokerImpl</attribute>
- </mbean>
+ <!-- An EJB Timer Service that is Tx aware -->
+ <mbean code="org.jboss.ejb.txtimer.EJBTimerServiceImpl"
+ name="jboss.ejb:service=EJBTimerService">
+ <attribute name="RetryPolicy">jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay</attribute>
+ <attribute name="PersistencePolicy">jboss.ejb:service=EJBTimerService,persistencePolicy=database</attribute>
+ <attribute name="TimerIdGeneratorClassName">org.jboss.ejb.txtimer.BigIntegerTimerIdGenerator</attribute>
+ <attribute name="TimedObjectInvokerClassName">org.jboss.ejb.txtimer.TimedObjectInvokerImpl</attribute>
+ </mbean>
- <!-- A retry policy that uses a fixed interval in milli seconds -->
- <mbean code="org.jboss.ejb.txtimer.FixedDelayRetryPolicy" name="jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay">
- <attribute name="Delay">100</attribute>
- </mbean>
+ <!-- A retry policy that uses a fixed interval in milli seconds -->
+ <mbean code="org.jboss.ejb.txtimer.FixedDelayRetryPolicy" name="jboss.ejb:service=EJBTimerService,retryPolicy=fixedDelay">
+ <attribute name="Delay">100</attribute>
+ </mbean>
- <!-- A persistence policy that does not persist the timer
- <mbean code="org.jboss.ejb.txtimer.NoopPersistencePolicy" name="jboss.ejb:service=EJBTimerService,persistencePolicy=noop"/>
- -->
+ <!-- A persistence policy that does not persist the timer
+ <mbean code="org.jboss.ejb.txtimer.NoopPersistencePolicy" name="jboss.ejb:service=EJBTimerService,persistencePolicy=noop"/>
+ -->
- <!-- A persistence policy that persistes timers to a database -->
- <mbean code="org.jboss.ejb.txtimer.DatabasePersistencePolicy" name="jboss.ejb:service=EJBTimerService,persistencePolicy=database">
- <!-- DataSource JNDI name -->
- <depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
- <!-- table name -->
- <attribute name="TableName">TIMERS</attribute>
- <!-- Column that contains the timer id -->
- <attribute name="TimerIdColumn">TIMERID</attribute>
- <!-- Column that contains the target component id -->
- <attribute name="TargetIdColumn">TARGETID</attribute>
- <!-- Column that contains the initial date value -->
- <attribute name="InitialDateColumn">INITIALDATE</attribute>
- <!-- Column that contains the optional interval value -->
- <attribute name="IntervalColumn">INTERVAL</attribute>
- <!-- Column that contains the optional entity bean pk object -->
- <attribute name="InstancePkColumn">INSTANCEPK</attribute>
- <!-- Column that contains the optional info object -->
- <attribute name="InfoColumn">INFO</attribute>
- <!-- Create table DDL -->
- <attribute name="CreateTableDDL">
- create table TIMERS (
- TIMERID varchar(50) not null,
- TARGETID varchar(50) not null,
- INITIALDATE timestamp not null,
- INTERVAL bigint,
- INSTANCEPK other,
- INFO other,
- constraint timers_pk primary key (TIMERID)
- )
- </attribute>
- </mbean>
+ <!-- A persistence policy that persistes timers to a database -->
+ <mbean code="org.jboss.ejb.txtimer.DatabasePersistencePolicy" name="jboss.ejb:service=EJBTimerService,persistencePolicy=database">
+ <!-- DataSource JNDI name -->
+ <depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
+ <!-- The plugin that handles database persistence -->
+ <attribute name="DatabasePersistencePlugin">org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin</attribute>
+ </mbean>
- <!-- ==================================================================== -->
- <!-- EJB Deployer -->
- <!-- ==================================================================== -->
+ <!-- ==================================================================== -->
+ <!-- EJB Deployer -->
+ <!-- ==================================================================== -->
- <!-- EJB deployer, remove to disable EJB behavior-->
- <mbean code="org.jboss.ejb.EJBDeployer" name="jboss.ejb:service=EJBDeployer">
- <!-- A flag indicating if the deployer should validate the
- ejb-jar.xml/jboss.xml descriptors and components
- -->
- <attribute name="VerifyDeployments">true</attribute>
- <!-- A flag indicating if the xml parser should validate the descriptor
- DTDs
- -->
- <attribute name="ValidateDTDs">false</attribute>
- <!-- A flag indicating if the verifier should be verbose about its
- operation
- -->
- <attribute name="VerifierVerbose">true</attribute>
- <!-- Setting this to 'true' will cause all deployments
- to fail when the Verifier detected a problem with the contained
- Beans. If false, warnings/errors will be logged but the deployment
- will not fail.
- -->
- <attribute name="StrictVerifier">true</attribute>
+ <!-- EJB deployer, remove to disable EJB behavior-->
+ <mbean code="org.jboss.ejb.EJBDeployer" name="jboss.ejb:service=EJBDeployer">
+ <!-- A flag indicating if the deployer should validate the
+ ejb-jar.xml/jboss.xml descriptors and components
+ -->
+ <attribute name="VerifyDeployments">true</attribute>
+ <!-- A flag indicating if the xml parser should validate the descriptor
+ DTDs
+ -->
+ <attribute name="ValidateDTDs">false</attribute>
+ <!-- A flag indicating if the verifier should be verbose about its
+ operation
+ -->
+ <attribute name="VerifierVerbose">true</attribute>
+ <!-- Setting this to 'true' will cause all deployments
+ to fail when the Verifier detected a problem with the contained
+ Beans. If false, warnings/errors will be logged but the deployment
+ will not fail.
+ -->
+ <attribute name="StrictVerifier">true</attribute>
- <!-- The EJBDeployer needs the JTA transaction manager service -->
- <depends optional-attribute-name="TransactionManagerServiceName">jboss:service=TransactionManager</depends>
- <!-- The dynamic class loading simple web server -->
- <depends optional-attribute-name="WebServiceName">jboss:service=WebService</depends>
- </mbean>
+ <!-- The EJBDeployer needs the JTA transaction manager service -->
+ <depends optional-attribute-name="TransactionManagerServiceName">jboss:service=TransactionManager</depends>
+ <!-- The dynamic class loading simple web server -->
+ <depends optional-attribute-name="WebServiceName">jboss:service=WebService</depends>
+ </mbean>
</server>
Added: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePlugin.java
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePlugin.java (rev 0)
+++ branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePlugin.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.ejb.txtimer;
+
+// $Id$
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.io.Serializable;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * An implementation of of this interface provides database specific JDBC access that is
+ * not portable accros RDBMS systems.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 23-Sep-2004
+ */
+public interface DatabasePersistencePlugin
+{
+ /** Initialize the plugin */
+ void init(MBeanServer server, ObjectName dataSource) throws SQLException;
+
+ /** Create the timers table if it does not exist already */
+ void createTableIfNotExists() throws SQLException;
+
+ /** Insert a timer object */
+ void insertTimer(String timerId, TimedObjectId timedObjectId, Date initialExpiration, long intervalDuration, Serializable info) throws SQLException;
+
+ /** Select a list of currently persisted timer handles
+ * @return List<TimerHandleImpl>
+ */
+ List selectTimers() throws SQLException;
+
+ /** Delete a timer. */
+ void deleteTimer(String timerId, TimedObjectId timedObjectId) throws SQLException;
+
+ /** Clear all persisted timers */
+ void clearTimers() throws SQLException;
+
+ /** Get the timer table name */
+ String getTableName();
+
+ /** Get the timer ID column name */
+ String getColumnTimerID();
+
+ /** Get the target ID column name */
+ String getColumnTargetID();
+
+ /** Get the initial date column name */
+ String getColumnInitialDate();
+
+ /** Get the timer interval column name */
+ String getColumnTimerInterval();
+
+ /** Get the instance PK column name */
+ String getColumnInstancePK();
+
+ /** Get the info column name */
+ String getColumnInfo();
+}
Property changes on: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePlugin.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java 2007-06-27 18:31:52 UTC (rev 63697)
+++ branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -9,7 +9,6 @@
// $Id$
import org.jboss.ejb.ContainerMBean;
-import org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil;
import org.jboss.logging.Logger;
import org.jboss.mx.util.MBeanProxy;
import org.jboss.mx.util.ObjectNameFactory;
@@ -24,57 +23,48 @@
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.io.Serializable;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
- * This service implements a PersistencePolicy that persistes the timer to a database.
+ * This service implements a PersistencePolicy that persistes the timer to a
+ * database.
*
* @author Thomas.Diesler at jboss.org
+ * @author Scott.Stark at jboss.org
* @jmx.mbean name="jboss.ejb:service=EJBTimerService,persistencePolicy=database"
* extends="org.jboss.system.Service, org.jboss.ejb.txtimer.PersistencePolicy"
* @since 09-Sep-2004
+ * @version $Revision$
*/
-public class DatabasePersistencePolicy extends ServiceMBeanSupport implements NotificationListener, DatabasePersistencePolicyMBean
+public class DatabasePersistencePolicy extends ServiceMBeanSupport
+ implements NotificationListener, DatabasePersistencePolicyMBean
{
// logging support
private static Logger log = Logger.getLogger(DatabasePersistencePolicy.class);
+ // The persistence plugin
+ private DatabasePersistencePlugin dbpPlugin;
+
// The service attributes
private ObjectName dataSource;
- private String tableName;
- private String timerIdColumn;
- private String targetIdColumn;
- private String initialDateColumn;
- private String intervalColumn;
- private String instancePkColumn;
- private String infoColumn;
- private String createTableDDL;
+ private String dbpPluginClassName;
+ // The transaction manager, to suspend the current Tx during delete
private TransactionManager tm;
- // The data source the timers will be persisted to
- private DataSource ds;
- // True when the table has been created
- private boolean tableCreated;
+ /** The peristed timers seen on startup */
+ private List timersToRestore;
/**
* Initializes this service.
*/
- protected void startService() throws Exception
+ public void startService() throws Exception
{
// Get the Tx manager
try
@@ -88,19 +78,31 @@
tm = TxManager.getInstance();
}
- try
+ // Get the persistence plugin
+ if (dbpPluginClassName != null)
{
- String dsJndiTx = (String)server.getAttribute(dataSource, "BindName");
- ds = (DataSource)new InitialContext().lookup(dsJndiTx);
+ Class dbpPolicyClass = Thread.currentThread().getContextClassLoader().loadClass(dbpPluginClassName);
+ dbpPlugin = (DatabasePersistencePlugin)dbpPolicyClass.newInstance();
}
- catch (NamingException e)
+ else
{
- throw new Exception("Failed to lookup data source: " + dataSource);
+ dbpPlugin = new GeneralPurposeDatabasePersistencePlugin();
}
+ // init the plugin
+ dbpPlugin.init(server, dataSource);
+
// create the table if needed
- createTableIfNotExists();
+ dbpPlugin.createTableIfNotExists();
+ timersToRestore = dbpPlugin.selectTimers();
+ log.debug("Found " + timersToRestore.size() + " timer(s)");
+ if (timersToRestore.size() > 0)
+ {
+ // delete all timers
+ dbpPlugin.clearTimers();
+ }
+
// await the server startup notification
registerNotificationListener();
}
@@ -129,8 +131,7 @@
{
try
{
- createTableIfNotExists();
- doInsertTimer(timerId, timedObjectId, firstEvent, intervalDuration, info);
+ dbpPlugin.insertTimer(timerId, timedObjectId, firstEvent, intervalDuration, info);
}
catch (SQLException e)
{
@@ -145,17 +146,24 @@
*
* @param timerId The timer id
*/
- public void deleteTimer(String timerId)
+ public void deleteTimer(String timerId, TimedObjectId timedObjectId)
{
+ // suspend the Tx before we get the con, because you cannot get a connection on an already commited Tx
+ Transaction threadTx = suspendTransaction();
+
try
{
- createTableIfNotExists();
- doDeleteTimer(timerId);
+ dbpPlugin.deleteTimer(timerId, timedObjectId);
}
catch (SQLException e)
{
log.warn("Unable to delete timer", e);
}
+ finally
+ {
+ // resume the Tx
+ resumeTransaction(threadTx);
+ }
}
/**
@@ -166,7 +174,7 @@
List list = new ArrayList();
try
{
- list.addAll(doSelectTimers());
+ list.addAll(dbpPlugin.selectTimers());
}
catch (SQLException e)
{
@@ -176,56 +184,44 @@
}
/**
- * Restore the persistet timers
+ * Restore the persistent timers seen during service startup
*/
public void restoreTimers()
{
- try
+ if (timersToRestore != null && timersToRestore.size() > 0)
{
- createTableIfNotExists();
+ log.debug("Restoring " + timersToRestore.size() + " timer(s)");
- List list = doSelectTimers();
- if (list.size() > 0)
+ // recreate the timers
+ for (int i = 0; i < timersToRestore.size(); i++)
{
- log.info("Restoring " + list.size() + " timer(s)");
+ TimerHandleImpl handle = (TimerHandleImpl)timersToRestore.get(i);
- // delete all timers
- doDeleteAllTimers();
-
- // recreate the timers
- for (int i = 0; i < list.size(); i++)
+ try
{
- TimerHandleImpl handle = (TimerHandleImpl)list.get(i);
-
- try
- {
- TimedObjectId targetId = handle.getTimedObjectId();
- ObjectName containerName = targetId.getContainerId();
- ContainerMBean container = (ContainerMBean)MBeanProxy.get(ContainerMBean.class, containerName, server);
- TimerService timerService = container.getTimerService(targetId.getInstancePk());
- timerService.createTimer(handle.getFirstTime(), handle.getPeriode(), handle.getInfo());
- }
- catch (Exception e)
- {
- log.warn("Unable to restore timer record: " + handle);
- }
+ TimedObjectId targetId = handle.getTimedObjectId();
+ ObjectName containerName = targetId.getContainerId();
+ ContainerMBean container = (ContainerMBean)MBeanProxy.get(ContainerMBean.class, containerName, server);
+ TimerService timerService = container.getTimerService(targetId.getInstancePk());
+ timerService.createTimer(handle.getFirstTime(), handle.getPeriode(), handle.getInfo());
}
+ catch (Exception e)
+ {
+ log.warn("Unable to restore timer record: " + handle);
+ }
}
+ timersToRestore.clear();
}
- catch (SQLException e)
- {
- log.warn("Unable to restore timers", e);
- }
}
/**
* Delete all persisted timers
*/
- public void deleteAllTimers()
+ public void clearTimers()
{
try
{
- doDeleteAllTimers();
+ dbpPlugin.clearTimers();
}
catch (SQLException e)
{
@@ -233,6 +229,23 @@
}
}
+ /** Re-read the current persistent timers list, clear the db of timers,
+ * and restore the timers.
+ *
+ * @jmx.managed-operation
+ */
+ public void resetAndRestoreTimers() throws SQLException
+ {
+ timersToRestore = dbpPlugin.selectTimers();
+ log.debug("Found " + timersToRestore.size() + " timer(s)");
+ if (timersToRestore.size() > 0)
+ {
+ // delete all timers
+ clearTimers();
+ }
+ restoreTimers();
+ }
+
// MBean attributes *************************************************************************************************\
/**
@@ -254,271 +267,20 @@
/**
* @jmx.managed-attribute
*/
- public String getTimerIdColumn()
+ public String getDatabasePersistencePlugin()
{
- return timerIdColumn;
+ return dbpPluginClassName;
}
/**
* @jmx.managed-attribute
*/
- public void setTimerIdColumn(String timerIdColumn)
+ public void setDatabasePersistencePlugin(String dbpPluginClass)
{
- this.timerIdColumn = timerIdColumn;
+ this.dbpPluginClassName = dbpPluginClass;
}
-
- /**
- * @jmx.managed-attribute
- */
- public String getInitialDateColumn()
- {
- return initialDateColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public void setInitialDateColumn(String initialDateColumn)
- {
- this.initialDateColumn = initialDateColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public String getIntervalColumn()
- {
- return intervalColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public void setIntervalColumn(String intervalColumn)
- {
- this.intervalColumn = intervalColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public String getTableName()
- {
- return tableName;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public void setTableName(String tableName)
- {
- this.tableName = tableName;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public String getTargetIdColumn()
- {
- return targetIdColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public void setTargetIdColumn(String targetIdColumn)
- {
- this.targetIdColumn = targetIdColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public String getInfoColumn()
- {
- return infoColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public void setInfoColumn(String infoColumn)
- {
- this.infoColumn = infoColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public String getInstancePkColumn()
- {
- return instancePkColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public void setInstancePkColumn(String instancePkColumn)
- {
- this.instancePkColumn = instancePkColumn;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public String getCreateTableDDL()
- {
- return createTableDDL;
- }
-
- /**
- * @jmx.managed-attribute
- */
- public void setCreateTableDDL(String createTableDDL)
- {
- this.createTableDDL = createTableDDL;
- }
-
// private **********************************************************************************************************
- private void createTableIfNotExists()
- throws SQLException
- {
- if (tableCreated == false)
- {
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- try
- {
- con = ds.getConnection();
- final DatabaseMetaData dbMD = con.getMetaData();
- rs = dbMD.getTables(null, null, tableName, null);
-
- if (!rs.next())
- {
- log.debug("Executing DDL: " + createTableDDL);
-
- st = con.createStatement();
- st.executeUpdate(createTableDDL);
- }
-
- tableCreated = true;
- }
- finally
- {
- JDBCUtil.safeClose(rs);
- JDBCUtil.safeClose(st);
- JDBCUtil.safeClose(con);
- }
- }
- }
-
- private void doInsertTimer(String timerId, TimedObjectId timedObjectId, Date initialExpiration, long intervalDuration, Serializable info)
- throws SQLException
- {
- Connection con = null;
- PreparedStatement st = null;
- try
- {
- // Use the Tx data source
- con = ds.getConnection();
-
- String sql = "insert into " + tableName + " " +
- "(" + timerIdColumn + "," + targetIdColumn + "," + initialDateColumn + "," + intervalColumn + "," + instancePkColumn + "," + infoColumn + ") " +
- "values (?,?,?,?,?,?)";
- st = con.prepareStatement(sql);
-
- st.setString(1, timerId);
- st.setString(2, timedObjectId.toString());
- st.setTimestamp(3, new Timestamp(initialExpiration.getTime()));
- st.setLong(4, intervalDuration);
- st.setObject(5, timedObjectId.getInstancePk());
- st.setObject(6, info);
-
- int rows = st.executeUpdate();
- if (rows != 1)
- log.error("Unable to insert timer for: " + timedObjectId);
- }
- finally
- {
- JDBCUtil.safeClose(st);
- JDBCUtil.safeClose(con);
- }
- }
-
- private List doSelectTimers()
- throws SQLException
- {
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- try
- {
- con = ds.getConnection();
-
- List list = new ArrayList();
-
- st = con.createStatement();
- rs = st.executeQuery("select * from " + tableName);
- while (rs.next())
- {
- String timerId = rs.getString(timerIdColumn);
- TimedObjectId targetId = TimedObjectId.parse(rs.getString(targetIdColumn));
- Date initialDate = rs.getTimestamp(initialDateColumn);
- long interval = rs.getLong(intervalColumn);
- Serializable pKey = (Serializable)rs.getObject(instancePkColumn);
- Serializable info = (Serializable)rs.getObject(infoColumn);
-
- targetId = new TimedObjectId(targetId.getContainerId(), pKey);
- TimerHandleImpl handle = new TimerHandleImpl(timerId, targetId, initialDate, interval, info);
- list.add(handle);
- }
-
- return list;
- }
- finally
- {
- JDBCUtil.safeClose(rs);
- JDBCUtil.safeClose(st);
- JDBCUtil.safeClose(con);
- }
- }
-
- private void doDeleteTimer(String timerId)
- throws SQLException
- {
- Connection con = null;
- PreparedStatement st = null;
- ResultSet rs = null;
-
- // suspend the Tx before we get the con, because you cannot get a connection on an already commited Tx
- Transaction threadTx = suspendTransaction();
-
- try
- {
- con = ds.getConnection();
-
- String sql = "delete from " + tableName + " where " + timerIdColumn + "=?";
- st = con.prepareStatement(sql);
-
- st.setString(1, timerId);
-
- int rows = st.executeUpdate();
- if (rows != 1)
- log.warn("Unable to remove timer for: " + timerId);
- }
- finally
- {
- // resume the Tx
- resumeTransaction(threadTx);
-
- JDBCUtil.safeClose(rs);
- JDBCUtil.safeClose(st);
- JDBCUtil.safeClose(con);
- }
- }
-
private Transaction suspendTransaction()
{
Transaction threadTx = null;
@@ -546,26 +308,6 @@
}
}
- private void doDeleteAllTimers()
- throws SQLException
- {
- Connection con = null;
- PreparedStatement st = null;
- ResultSet rs = null;
- try
- {
- con = ds.getConnection();
- st = con.prepareStatement("delete from " + tableName);
- st.executeUpdate();
- }
- finally
- {
- JDBCUtil.safeClose(rs);
- JDBCUtil.safeClose(st);
- JDBCUtil.safeClose(con);
- }
- }
-
/**
* Register this service as a listener to the main jboss server.
* We want the startup notification in order to restore our timers.
Added: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java (rev 0)
+++ branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -0,0 +1,366 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.ejb.txtimer;
+
+// $Id$
+
+import org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil;
+import org.jboss.ejb.plugins.cmp.jdbc.SQLUtil;
+import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCTypeMappingMetaData;
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.ObjectNameFactory;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * This DatabasePersistencePlugin uses getBytes/setBytes to persist the
+ * serializable objects associated with the timer.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 23-Sep-2004
+ */
+public class GeneralPurposeDatabasePersistencePlugin implements DatabasePersistencePlugin
+{
+ // logging support
+ private static Logger log = Logger.getLogger(GeneralPurposeDatabasePersistencePlugin.class);
+
+ // The service attributes
+ protected ObjectName dataSourceName;
+
+ // The mbean server
+ protected MBeanServer server;
+ // The data source the timers will be persisted to
+ protected DataSource ds;
+ // datasource meta data
+ protected ObjectName metaDataName;
+
+ /** Initialize the plugin */
+ public void init(MBeanServer server, ObjectName dataSourceName) throws SQLException
+ {
+ this.server = server;
+ this.dataSourceName = dataSourceName;
+
+ // Get the DataSource from JNDI
+ try
+ {
+ String dsJndiTx = (String)server.getAttribute(dataSourceName, "BindName");
+ ds = (DataSource)new InitialContext().lookup(dsJndiTx);
+ }
+ catch (Exception e)
+ {
+ throw new SQLException("Failed to lookup data source: " + dataSourceName);
+ }
+
+ // Get the DataSource meta data
+ String dsName = dataSourceName.getKeyProperty("name");
+ metaDataName = ObjectNameFactory.create("jboss.jdbc:datasource=" + dsName + ",service=metadata");
+ if (this.server.isRegistered(metaDataName) == false)
+ throw new IllegalStateException("Cannot find datasource meta data: " + metaDataName);
+ }
+
+ /** Create the timer table if it does not exist already */
+ public void createTableIfNotExists()
+ throws SQLException
+ {
+ Connection con = null;
+ Statement st = null;
+ try
+ {
+ if (!SQLUtil.tableExists(getTableName(), ds))
+ {
+ con = ds.getConnection();
+ JDBCTypeMappingMetaData typeMapping = (JDBCTypeMappingMetaData)server.getAttribute(metaDataName, "TypeMappingMetaData");
+ if (typeMapping == null)
+ throw new IllegalStateException("Cannot obtain type mapping from: " + metaDataName);
+
+ String dateType = typeMapping.getTypeMappingMetaData(Timestamp.class).getSqlType();
+ String objectType = typeMapping.getTypeMappingMetaData(Object.class).getSqlType();
+ String longType = typeMapping.getTypeMappingMetaData(Long.class).getSqlType();
+
+ String createTableDDL = "create table " + getTableName() + " (" +
+ " " + getColumnTimerID() + " varchar(80) not null," +
+ " " + getColumnTargetID() + " varchar(80) not null," +
+ " " + getColumnInitialDate() + " " + dateType + " not null," +
+ " " + getColumnTimerInterval() + " " + longType + "," +
+ " " + getColumnInstancePK() + " " + objectType + "," +
+ " " + getColumnInfo() + " " + objectType + "," +
+ " constraint " + getTableName() + "_PK primary key (" + getColumnTimerID() + "," + getColumnTargetID() + ")" +
+ ")";
+
+ log.debug("Executing DDL: " + createTableDDL);
+
+ st = con.createStatement();
+ st.executeUpdate(createTableDDL);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot create timer table", e);
+ }
+ finally
+ {
+ JDBCUtil.safeClose(st);
+ JDBCUtil.safeClose(con);
+ }
+ }
+
+ /** Insert a timer object */
+ public void insertTimer(String timerId, TimedObjectId timedObjectId, Date initialExpiration, long intervalDuration, Serializable info)
+ throws SQLException
+ {
+ Connection con = null;
+ PreparedStatement st = null;
+ try
+ {
+ con = ds.getConnection();
+
+ String sql = "insert into " + getTableName() + " " +
+ "(" + getColumnTimerID() + "," + getColumnTargetID() + "," + getColumnInitialDate() + "," + getColumnTimerInterval() + "," + getColumnInstancePK() + "," + getColumnInfo() + ") " +
+ "values (?,?,?,?,?,?)";
+ st = con.prepareStatement(sql);
+
+ st.setString(1, timerId);
+ st.setString(2, timedObjectId.toString());
+ st.setTimestamp(3, new Timestamp(initialExpiration.getTime()));
+ st.setLong(4, intervalDuration);
+ st.setBytes(5, serialize(timedObjectId.getInstancePk()));
+ st.setBytes(6, serialize(info));
+
+ int rows = st.executeUpdate();
+ if (rows != 1)
+ log.error("Unable to insert timer for: " + timedObjectId);
+ }
+ finally
+ {
+ JDBCUtil.safeClose(st);
+ JDBCUtil.safeClose(con);
+ }
+ }
+
+ /** Select a list of currently persisted timer handles
+ * @return List<TimerHandleImpl>
+ */
+ public List selectTimers()
+ throws SQLException
+ {
+ Connection con = null;
+ Statement st = null;
+ ResultSet rs = null;
+ try
+ {
+ con = ds.getConnection();
+
+ List list = new ArrayList();
+
+ st = con.createStatement();
+ rs = st.executeQuery("select * from " + getTableName());
+ while (rs.next())
+ {
+ String timerId = rs.getString(getColumnTimerID());
+ TimedObjectId targetId = TimedObjectId.parse(rs.getString(getColumnTargetID()));
+ Date initialDate = rs.getTimestamp(getColumnInitialDate());
+ long interval = rs.getLong(getColumnTimerInterval());
+ Serializable pKey = (Serializable)deserialize(rs.getBytes(getColumnInstancePK()));
+ Serializable info = (Serializable)deserialize(rs.getBytes(getColumnInfo()));
+
+ targetId = new TimedObjectId(targetId.getContainerId(), pKey);
+ TimerHandleImpl handle = new TimerHandleImpl(timerId, targetId, initialDate, interval, info);
+ list.add(handle);
+ }
+
+ return list;
+ }
+ finally
+ {
+ JDBCUtil.safeClose(rs);
+ JDBCUtil.safeClose(st);
+ JDBCUtil.safeClose(con);
+ }
+ }
+
+ /** Delete a timer. */
+ public void deleteTimer(String timerId, TimedObjectId timedObjectId)
+ throws SQLException
+ {
+ Connection con = null;
+ PreparedStatement st = null;
+ ResultSet rs = null;
+
+ try
+ {
+ con = ds.getConnection();
+
+ String sql = "delete from " + getTableName() + " where " + getColumnTimerID() + "=? and " + getColumnTargetID() + "=?";
+ st = con.prepareStatement(sql);
+
+ st.setString(1, timerId);
+ st.setString(2, timedObjectId.toString());
+
+ int rows = st.executeUpdate();
+ if (rows != 1)
+ log.warn("Unable to remove timer for: " + timerId);
+ }
+ finally
+ {
+ JDBCUtil.safeClose(rs);
+ JDBCUtil.safeClose(st);
+ JDBCUtil.safeClose(con);
+ }
+ }
+
+ /** Clear all persisted timers */
+ public void clearTimers()
+ throws SQLException
+ {
+ Connection con = null;
+ PreparedStatement st = null;
+ ResultSet rs = null;
+ try
+ {
+ con = ds.getConnection();
+ st = con.prepareStatement("delete from " + getTableName());
+ st.executeUpdate();
+ }
+ finally
+ {
+ JDBCUtil.safeClose(rs);
+ JDBCUtil.safeClose(st);
+ JDBCUtil.safeClose(con);
+ }
+ }
+
+ /** Get the timer table name */
+ public String getTableName()
+ {
+ return "TIMERS";
+ }
+
+ /** Get the timer ID column name */
+ public String getColumnTimerID()
+ {
+ return "TIMERID";
+ }
+
+ /** Get the target ID column name */
+ public String getColumnTargetID()
+ {
+ return "TARGETID";
+ }
+
+ /** Get the initial date column name */
+ public String getColumnInitialDate()
+ {
+ return "INITIALDATE";
+ }
+
+ /** Get the timer interval column name */
+ public String getColumnTimerInterval()
+ {
+ // Note 'INTERVAL' is a reserved word in MySQL
+ return "TIMERINTERVAL";
+ }
+
+ /** Get the instance PK column name */
+ public String getColumnInstancePK()
+ {
+ return "INSTANCEPK";
+ }
+
+ /** Get the info column name */
+ public String getColumnInfo()
+ {
+ return "INFO";
+ }
+
+ /** Serialize an object */
+ protected byte[] serialize(Object obj)
+ {
+
+ if (obj == null)
+ return null;
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ try
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(obj);
+ oos.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Cannot serialize: " + obj, e);
+ }
+ return baos.toByteArray();
+ }
+
+ /** Deserialize an object */
+ protected Object deserialize(byte[] bytes)
+ {
+
+ if (bytes == null)
+ return null;
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ try
+ {
+ ObjectInputStream oos = new ObjectInputStream(bais);
+ return oos.readObject();
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot deserialize", e);
+ return null;
+ }
+ }
+
+ /** Deserialize an object */
+ protected Object deserialize(InputStream input)
+ {
+
+ if (input == null)
+ return null;
+
+ byte[] barr = new byte[1024];
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ try
+ {
+ for (int b = 0; (b = input.read(barr)) > 0;)
+ {
+ baos.write(barr, 0, b);
+ }
+ return deserialize(baos.toByteArray());
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot deserialize", e);
+ return null;
+ }
+ }
+}
Property changes on: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/NoopPersistencePolicy.java
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/NoopPersistencePolicy.java 2007-06-27 18:31:52 UTC (rev 63697)
+++ branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/NoopPersistencePolicy.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -47,8 +47,9 @@
* Removes the timer from persistent storage.
*
* @param timerId The timer id
+ * @param timedObjectId The id of the timed object
*/
- public void deleteTimer(String timerId)
+ public void deleteTimer(String timerId, TimedObjectId timedObjectId)
{
log.debug("Noop on destroyTimer");
}
@@ -73,7 +74,7 @@
/**
* Delete all persisted timers
*/
- public void deleteAllTimers()
+ public void clearTimers()
{
log.debug("Noop on deleteAllTimers");
}
Added: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/OracleDatabasePersistencePlugin.java
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/OracleDatabasePersistencePlugin.java (rev 0)
+++ branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/OracleDatabasePersistencePlugin.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.ejb.txtimer;
+
+// $Id$
+
+import org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil;
+import org.jboss.logging.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * This DatabasePersistencePlugin uses getBinaryStream/setBinaryStream to persist the
+ * serializable objects associated with the timer.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 23-Sep-2004
+ */
+public class OracleDatabasePersistencePlugin extends GeneralPurposeDatabasePersistencePlugin
+{
+ // logging support
+ private static Logger log = Logger.getLogger(OracleDatabasePersistencePlugin.class);
+
+ /** Insert a timer object */
+ public void insertTimer(String timerId, TimedObjectId timedObjectId, Date initialExpiration, long intervalDuration, Serializable info)
+ throws SQLException
+ {
+ Connection con = null;
+ PreparedStatement st = null;
+ try
+ {
+ con = ds.getConnection();
+
+ String sql = "insert into " + getTableName() + " " +
+ "(" + getColumnTimerID() + "," + getColumnTargetID() + "," + getColumnInitialDate() + "," + getColumnTimerInterval() + "," + getColumnInstancePK() + "," + getColumnInfo() + ") " +
+ "values (?,?,?,?,?,?)";
+ st = con.prepareStatement(sql);
+
+ st.setString(1, timerId);
+ st.setString(2, timedObjectId.toString());
+ st.setTimestamp(3, new Timestamp(initialExpiration.getTime()));
+ st.setLong(4, intervalDuration);
+
+ byte[] pkArr = serialize(timedObjectId.getInstancePk());
+ if (pkArr != null)
+ {
+ InputStream is = new ByteArrayInputStream(pkArr);
+ st.setBinaryStream(5, is, pkArr.length);
+ }
+ else
+ {
+ st.setBytes(5, null);
+ }
+
+ byte[] infoArr = serialize(info);
+ if (infoArr != null)
+ {
+ InputStream is = new ByteArrayInputStream(infoArr);
+ st.setBinaryStream(6, is, infoArr.length);
+ }
+ else
+ {
+ st.setBytes(6, null);
+ }
+
+ int rows = st.executeUpdate();
+ if (rows != 1)
+ log.error("Unable to insert timer for: " + timedObjectId);
+ }
+ finally
+ {
+ JDBCUtil.safeClose(st);
+ JDBCUtil.safeClose(con);
+ }
+ }
+
+ /** Select a list of currently persisted timer handles
+ * @return List<TimerHandleImpl>
+ */
+ public List selectTimers()
+ throws SQLException
+ {
+ Connection con = null;
+ Statement st = null;
+ ResultSet rs = null;
+ try
+ {
+ con = ds.getConnection();
+
+ List list = new ArrayList();
+
+ st = con.createStatement();
+ rs = st.executeQuery("select * from " + getTableName());
+ while (rs.next())
+ {
+ String timerId = rs.getString(getColumnTimerID());
+ TimedObjectId targetId = TimedObjectId.parse(rs.getString(getColumnTargetID()));
+ Date initialDate = rs.getTimestamp(getColumnInitialDate());
+ long interval = rs.getLong(getColumnTimerInterval());
+
+ InputStream isPk = rs.getBinaryStream(getColumnInstancePK());
+ Serializable pKey = (Serializable)deserialize(isPk);
+ InputStream isInfo = rs.getBinaryStream(getColumnInfo());
+ Serializable info = (Serializable)deserialize(isInfo);
+
+ targetId = new TimedObjectId(targetId.getContainerId(), pKey);
+ TimerHandleImpl handle = new TimerHandleImpl(timerId, targetId, initialDate, interval, info);
+ list.add(handle);
+ }
+
+ return list;
+ }
+ finally
+ {
+ JDBCUtil.safeClose(rs);
+ JDBCUtil.safeClose(st);
+ JDBCUtil.safeClose(con);
+ }
+ }
+}
Property changes on: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/OracleDatabasePersistencePlugin.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/PersistencePolicy.java
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/PersistencePolicy.java 2007-06-27 18:31:52 UTC (rev 63697)
+++ branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/PersistencePolicy.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -38,13 +38,14 @@
* Deletes a timer from persistent storage.
*
* @param timerId The timer id
+ * @param timedObjectId The id of the timed object
*/
- void deleteTimer(String timerId);
+ void deleteTimer(String timerId, TimedObjectId timedObjectId);
/**
* Clear the persisted timers
*/
- void deleteAllTimers();
+ void clearTimers();
/**
* Restore the persistet timers
Modified: branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java
===================================================================
--- branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java 2007-06-27 18:31:52 UTC (rev 63697)
+++ branches/JBoss_4_0_0_CP/server/src/main/org/jboss/ejb/txtimer/TimerServiceImpl.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -45,8 +45,8 @@
private TimedObjectId timedObjectId;
private TimedObjectInvoker timedObjectInvoker;
- // The shared timerId generator
- private static TimerIdGenerator timerIdGenerator;
+ // The timerId generator
+ private TimerIdGenerator timerIdGenerator;
// Map<TimerHandleImpl,TimerImpl>
private Map timers = new HashMap();
@@ -87,21 +87,18 @@
}
// Get the timerId generator
- if (timerIdGenerator == null)
+ try
{
- try
- {
- MBeanServer server = MBeanServerLocator.locateJBoss();
- String timerIdGeneratorClassName = (String)server.getAttribute(EJBTimerService.OBJECT_NAME, "TimerIdGeneratorClassName");
- Class timerIdGeneratorClass = getClass().getClassLoader().loadClass(timerIdGeneratorClassName);
- timerIdGenerator = (TimerIdGenerator)timerIdGeneratorClass.newInstance();
- }
- catch (Exception e)
- {
- log.warn("Cannot obtain the implementation of a TimerIdGenerator: " + e.toString());
- timerIdGenerator = new BigIntegerTimerIdGenerator();
- }
+ MBeanServer server = MBeanServerLocator.locateJBoss();
+ String timerIdGeneratorClassName = (String)server.getAttribute(EJBTimerService.OBJECT_NAME, "TimerIdGeneratorClassName");
+ Class timerIdGeneratorClass = getClass().getClassLoader().loadClass(timerIdGeneratorClassName);
+ timerIdGenerator = (TimerIdGenerator)timerIdGeneratorClass.newInstance();
}
+ catch (Exception e)
+ {
+ log.warn("Cannot obtain the implementation of a TimerIdGenerator: " + e.toString());
+ timerIdGenerator = new BigIntegerTimerIdGenerator();
+ }
}
/**
@@ -336,7 +333,7 @@
{
synchronized (timers)
{
- persistencePolicy.deleteTimer(txtimer.getTimerId());
+ persistencePolicy.deleteTimer(txtimer.getTimerId(), txtimer.getTimedObjectId());
timers.remove(new TimerHandleImpl(txtimer));
}
}
Modified: branches/JBoss_4_0_0_CP/testsuite/.classpath
===================================================================
--- branches/JBoss_4_0_0_CP/testsuite/.classpath 2007-06-27 18:31:52 UTC (rev 63697)
+++ branches/JBoss_4_0_0_CP/testsuite/.classpath 2007-06-27 18:33:30 UTC (rev 63698)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="org/jboss/test/media/|org/jboss/test/webservice/" kind="src" path="src/main"/>
+ <classpathentry kind="src" path="src/resources"/>
<classpathentry excluding="org/jboss/test/webservice/" kind="src" path="output/gen-src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/tools"/>
Modified: branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/txtimer/test/PersistenceTestCase.java
===================================================================
--- branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/txtimer/test/PersistenceTestCase.java 2007-06-27 18:31:52 UTC (rev 63697)
+++ branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/txtimer/test/PersistenceTestCase.java 2007-06-27 18:33:30 UTC (rev 63698)
@@ -9,7 +9,7 @@
// $Id$
import junit.framework.TestSuite;
-import org.jboss.ejb.txtimer.DatabasePersistencePolicy;
+import org.jboss.ejb.txtimer.DatabasePersistencePolicyMBean;
import org.jboss.ejb.txtimer.PersistencePolicy;
import org.jboss.ejb.txtimer.TimedObjectId;
import org.jboss.ejb.txtimer.TimerHandleImpl;
@@ -22,6 +22,7 @@
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
+import javax.management.MBeanServerInvocationHandler;
import javax.naming.InitialContext;
import java.io.Serializable;
import java.util.Date;
@@ -136,6 +137,7 @@
InitialContext iniCtx = getInitialContext();
TimerSessionHome home = (TimerSessionHome)iniCtx.lookup(TimerSessionHome.JNDI_NAME);
TimerSession session = home.create();
+ session.resetCallCount();
try
{
// insert a timer into the db
@@ -173,8 +175,8 @@
// insert a timer into the db
String timerId = "pk1";
- ObjectName oname = ObjectNameFactory.create("jboss.j2ee:jndiName=test/txtimer/TimerSession,service=EJB");
- TimedObjectId targetId = new TimedObjectId(oname, "pk");
+ ObjectName oname = ObjectNameFactory.create("jboss.j2ee:jndiName=test/txtimer/TimerEntity,service=EJB");
+ TimedObjectId targetId = new TimedObjectId(oname, new Integer(100));
Date firstEvent = new Date ();
String info = "info";
pp.insertTimer(timerId, targetId, firstEvent, 100, info);
@@ -189,7 +191,7 @@
assertEquals("periode is not equal", 100, handle.getPeriode());
assertEquals("info is not equal", info, handle.getInfo());
- pp.deleteAllTimers();
+ pp.clearTimers();
timerHandles = pp.listTimerHandles();
assertEquals("unexpected handle count", 0, timerHandles.size());
@@ -200,20 +202,21 @@
*/
static class PersistencePolicyDelegate implements PersistencePolicy
{
- MBeanServerConnection server;
+ DatabasePersistencePolicyMBean proxy;
public PersistencePolicyDelegate(MBeanServerConnection server)
{
- this.server = server;
+ proxy = (DatabasePersistencePolicyMBean)
+ MBeanServerInvocationHandler.newProxyInstance(server,
+ DatabasePersistencePolicyMBean.OBJECT_NAME,
+ DatabasePersistencePolicyMBean.class, false);
}
public void insertTimer(String timerId, TimedObjectId targetId, Date firstEvent, long periode, Serializable info)
{
try
{
- server.invoke(DatabasePersistencePolicy.OBJECT_NAME, "insertTimer",
- new Object[]{timerId, targetId, firstEvent, new Long(periode), info},
- new String[]{String.class.getName(), TimedObjectId.class.getName(), Date.class.getName(), long.class.getName(), Serializable.class.getName()});
+ proxy.insertTimer(timerId, targetId, firstEvent, periode, info);
}
catch (Exception e)
{
@@ -221,13 +224,11 @@
}
}
- public void deleteTimer(String timerId)
+ public void deleteTimer(String timerId, TimedObjectId targetId)
{
try
{
- server.invoke(DatabasePersistencePolicy.OBJECT_NAME, "deleteTimer",
- new Object[]{timerId},
- new String[]{String.class.getName()});
+ proxy.deleteTimer(timerId, targetId);
}
catch (Exception e)
{
@@ -235,11 +236,11 @@
}
}
- public void deleteAllTimers()
+ public void clearTimers()
{
try
{
- server.invoke(DatabasePersistencePolicy.OBJECT_NAME, "deleteAllTimers", null, null);
+ proxy.clearTimers();
}
catch (Exception e)
{
@@ -251,7 +252,7 @@
{
try
{
- server.invoke(DatabasePersistencePolicy.OBJECT_NAME, "restoreTimers", null, null);
+ proxy.resetAndRestoreTimers();
}
catch (Exception e)
{
@@ -263,9 +264,8 @@
{
List list = null;
try
- {
-
- list = (List)server.invoke(DatabasePersistencePolicy.OBJECT_NAME, "listTimerHandles", null, null);
+ {
+ list = proxy.listTimerHandles();
}
catch (Exception e)
{
More information about the jboss-cvs-commits
mailing list