FileDocCategorySizeDatePackage
StatefulHASessionSynchronisationInterceptor.javaAPI DocJBoss 4.2.15583Fri Jul 13 20:52:34 BST 2007org.jboss.ejb.plugins

StatefulHASessionSynchronisationInterceptor

public class StatefulHASessionSynchronisationInterceptor extends AbstractInterceptor
This interceptor synchronizes a HA SFSB instance with its underlying persistent manager.
author
Sacha Labourey
version
$Revision: 57188 $

Revisions:

2002/07/28: Sacha Labourey

  1. Added isModified check before replication (TaskId 57031)

Fields Summary
protected org.jboss.ejb.StatefulSessionContainer
container
protected Method
isModified
Constructors Summary
Methods Summary
public org.jboss.ejb.ContainergetContainer()

      return container;
   
public java.lang.Objectinvoke(org.jboss.invocation.Invocation mi)

      EnterpriseContext ctx = (EnterpriseContext)mi.getEnterpriseContext ();
      
      try
      {
         // Invoke through interceptors
         return getNext ().invoke (mi);
      }
      catch (RemoteException e)
      {
         ctx = null;
         throw e;
      }
      catch (RuntimeException e)
      {
         ctx = null;
         throw e;
      }
      catch (Error e)
      {
         ctx = null;
         throw e;
      }
      finally
      {
         if ( (ctx != null) && (ctx.getId () != null) )
            // Still a valid instance and instance not removed
            //
         {
            // Everything went ok (at least no J2EE problem) and the instance will most probably be called
            // many more times. Consequently, we need to synchronize the state of our bean instance with
            // our persistant store (which will forward this to its HASessionState implementation) for clustering
            // behaviour.
            //
            
            if(isModified == null)
            {
               synchronizeState (ctx);
            }
            else
            {
               Boolean modified = (Boolean) isModified.invoke (ctx.getInstance (), new Object[0]);
               if (modified.booleanValue ())
                  synchronizeState (ctx);
            }
         }
      }
   
public java.lang.ObjectinvokeHome(org.jboss.invocation.Invocation mi)

      EnterpriseContext ctx = (EnterpriseContext)mi.getEnterpriseContext ();
      
      try
      {
         // Invoke through interceptors
         return getNext ().invokeHome (mi);
      }
      finally
      {
         if ( (ctx != null) && (ctx.getId () != null) )
            // Still a valid instance and instance not removed
            //
         {
            // Everything went ok (at least no J2EE problem) and the instance will most probably be called
            // many more times. Consequently, we need to synchronize the state of our bean instance with
            // our persistant store (which will forward this to its HASessionState implementation) for clustering
            // behaviour. This is only necessary for "create" calls (which is the case because ctx.getId() != null)
            //
            synchronizeState (ctx);
         }
      }
   
public voidsetContainer(org.jboss.ejb.Container container)
This callback is set by the container so that the plugin may access it

param
container The container using this plugin.

      this.container = (StatefulSessionContainer)container;
   
public voidstart()


        
   
      // Lookup the isModified method if it exists
      //
      try
      {
         isModified = this.container.getBeanClass().getMethod("isModified", new Class[0]);
         if (!isModified.getReturnType().equals(Boolean.TYPE)) {
            isModified = null; // Has to have "boolean" as return type!
            log.warn("Found isModified method, but return type is not boolean; ignoring");
         }
         else 
         {
            log.debug("Using isModified method: " + isModified);
         }
      }
      catch (NoSuchMethodException ignored) {}
   
protected voidsynchronizeState(org.jboss.ejb.EnterpriseContext ctx)

      ((HAPersistentManager)container.getPersistenceManager ()).synchroSession ((StatefulSessionEnterpriseContext)ctx);