[jbpm-commits] JBoss JBPM SVN: r1833 - jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Aug 6 05:16:01 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-08-06 05:16:01 -0400 (Wed, 06 Aug 2008)
New Revision: 1833

Added:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java
Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
Log:
removed dependency on javax.transaction.Syncronization in ExceptionHandlerImpl

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java	2008-08-06 08:13:08 UTC (rev 1832)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java	2008-08-06 09:16:01 UTC (rev 1833)
@@ -25,21 +25,15 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
 
 import org.jbpm.pvm.PvmException;
 import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.EnvironmentFactory;
 import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.cmd.Command;
-import org.jbpm.pvm.internal.cmd.CommandService;
 import org.jbpm.pvm.internal.log.Log;
 import org.jbpm.pvm.internal.model.op.MoveToChildNode;
 import org.jbpm.pvm.internal.wire.Descriptor;
 import org.jbpm.pvm.listener.EventListener;
 import org.jbpm.pvm.model.ProcessDefinition;
-import org.jbpm.pvm.session.DbSession;
 
 /**
  * @author Tom Baeyens
@@ -47,7 +41,7 @@
 public class ExceptionHandlerImpl implements Serializable {
 
   private static final long serialVersionUID = 1L;
-  private static final Log log = Log.getLog(ExceptionHandlerImpl.class.getName());
+  static final Log log = Log.getLog(ExceptionHandlerImpl.class.getName());
 
   protected long dbid;
   protected int dbversion;
@@ -127,12 +121,14 @@
       Transaction transaction = (environment!=null ? environment.get(Transaction.class) : null);
       if (transaction!=null) {
         log.trace("registering exception handler to "+transaction);
-        AfterTxCompletionListener afterTxCompletionListener = new AfterTxCompletionListener(
-                execution, 
+        ExceptionHandlerSynchronization exceptionHandlerSynchronization = new ExceptionHandlerSynchronization(
+                this, execution, 
                 exception,
                 environment.getEnvironmentFactory()
         );
-        transaction.registerSynchronization(afterTxCompletionListener);
+        // registration of the synchronization is delegated to the AfterTxCompletionListener
+        // to avoid a dependency on class Synchronization
+        exceptionHandlerSynchronization.register(transaction);
         log.trace("registering exception handler to "+transaction);
         throw new PvmException("transaction exception handler registered handler after transaction completed.  make sure this transaction is rolled back", exception); 
       } else {
@@ -143,7 +139,7 @@
     }
   }
   
-  private void executeHandler(ExecutionImpl execution, Exception exception) {
+  void executeHandler(ExecutionImpl execution, Exception exception) {
     if (eventListenerReferences!=null) {
       for (ObjectReference<EventListener> eventListenerReference: eventListenerReferences) {
         
@@ -216,46 +212,6 @@
     }
   }
 
-  private class AfterTxCompletionListener implements Synchronization, Command<Object> {
-
-    private static final long serialVersionUID = 1L;
-    
-    protected ExecutionImpl execution;
-    protected Exception exception;
-    protected EnvironmentFactory environmentFactory;
-
-    public AfterTxCompletionListener(ExecutionImpl execution, Exception exception, EnvironmentFactory environmentFactory) {
-      this.execution = execution;
-      this.exception = exception;
-      this.environmentFactory = environmentFactory;
-    }
-
-    public void afterCompletion(int status) {
-      if (status!=Status.STATUS_ROLLEDBACK) {
-        log.info("WARNING: no rollback after transactional exception handler. did you forget to rollback the transaction ?");
-      }
-      CommandService commandService = environmentFactory.get(CommandService.class);
-      if (commandService==null) {
-        throw new PvmException("environment factory doesn't have a command service");
-      }
-      commandService.execute(this);
-    }
-
-    public Object execute(Environment environment) {
-      // reload the execution
-      DbSession dbSession = environment.get(DbSession.class);
-      if (dbSession==null) {
-        throw new PvmException("no "+DbSession.class.getName()+" available in the environment for reloading the execution");
-      }
-      execution = dbSession.get(ExecutionImpl.class, execution.getDbid());
-      executeHandler(execution, exception);
-      return null;
-    }
-
-    public void beforeCompletion() {
-    }
-  }
-
   public static void rethrow(Exception exception, String prefixMessage) {
     log.trace("rethrowing "+exception);
     if (exception instanceof RuntimeException) {

Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java	2008-08-06 09:16:01 UTC (rev 1833)
@@ -0,0 +1,82 @@
+/*
+ * 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.jbpm.pvm.internal.model;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.env.EnvironmentFactory;
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.cmd.Command;
+import org.jbpm.pvm.internal.cmd.CommandService;
+import org.jbpm.pvm.session.DbSession;
+
+public class ExceptionHandlerSynchronization implements Synchronization, Command<Object> {
+
+  private final ExceptionHandlerImpl exceptionHandler;
+
+  private static final long serialVersionUID = 1L;
+  
+  protected ExecutionImpl execution;
+  protected Exception exception;
+  protected EnvironmentFactory environmentFactory;
+
+  public ExceptionHandlerSynchronization(ExceptionHandlerImpl exceptionHandler, ExecutionImpl execution, Exception exception, EnvironmentFactory environmentFactory) {
+    this.exceptionHandler = exceptionHandler;
+    this.execution = execution;
+    this.exception = exception;
+    this.environmentFactory = environmentFactory;
+  }
+
+  public void afterCompletion(int status) {
+    if (status!=Status.STATUS_ROLLEDBACK) {
+      ExceptionHandlerImpl.log.info("WARNING: no rollback after transactional exception handler. did you forget to rollback the transaction ?");
+    }
+    CommandService commandService = environmentFactory.get(CommandService.class);
+    if (commandService==null) {
+      throw new PvmException("environment factory doesn't have a command service");
+    }
+    commandService.execute(this);
+  }
+
+  public Object execute(Environment environment) {
+    // reload the execution
+    DbSession dbSession = environment.get(DbSession.class);
+    if (dbSession==null) {
+      throw new PvmException("no "+DbSession.class.getName()+" available in the environment for reloading the execution");
+    }
+    execution = dbSession.get(ExecutionImpl.class, execution.getDbid());
+    exceptionHandler.executeHandler(execution, exception);
+    return null;
+  }
+
+  public void beforeCompletion() {
+  }
+
+  public void register(Transaction transaction) {
+    // registration of the synchronization is delegated to the AfterTxCompletionListener
+    // to avoid a dependency on class Synchronization in class ExceptionHandlerImpl
+    transaction.registerSynchronization(this);
+  }
+}
\ No newline at end of file




More information about the jbpm-commits mailing list