1 22 package org.jboss.ejb.plugins; 23 24 import java.lang.reflect.Method ; 25 import java.rmi.RemoteException ; 26 27 import org.jboss.ejb.Container; 28 import org.jboss.ejb.StatefulSessionContainer; 29 import org.jboss.ejb.StatefulSessionEnterpriseContext; 30 import org.jboss.ejb.EnterpriseContext; 31 import org.jboss.invocation.Invocation; 32 33 45 public class StatefulHASessionSynchronisationInterceptor 46 extends AbstractInterceptor 47 { 48 protected StatefulSessionContainer container; 49 50 protected Method isModified = null; 53 54 public void start () throws Exception 55 { 56 try 59 { 60 isModified = this.container.getBeanClass().getMethod("isModified", new Class [0]); 61 if (!isModified.getReturnType().equals(Boolean.TYPE)) { 62 isModified = null; log.warn("Found isModified method, but return type is not boolean; ignoring"); 64 } 65 else 66 { 67 log.debug("Using isModified method: " + isModified); 68 } 69 } 70 catch (NoSuchMethodException ignored) {} 71 } 72 73 public Object invokeHome (Invocation mi) 74 throws Exception 75 { 76 EnterpriseContext ctx = (EnterpriseContext)mi.getEnterpriseContext (); 77 78 try 79 { 80 return getNext ().invokeHome (mi); 82 } 83 finally 84 { 85 if ( (ctx != null) && (ctx.getId () != null) ) 86 { 89 synchronizeState (ctx); 95 } 96 } 97 } 98 99 public Object invoke (Invocation mi) 100 throws Exception 101 { 102 EnterpriseContext ctx = (EnterpriseContext)mi.getEnterpriseContext (); 103 104 try 105 { 106 return getNext ().invoke (mi); 108 } 109 catch (RemoteException e) 110 { 111 ctx = null; 112 throw e; 113 } 114 catch (RuntimeException e) 115 { 116 ctx = null; 117 throw e; 118 } 119 catch (Error e) 120 { 121 ctx = null; 122 throw e; 123 } 124 finally 125 { 126 if ( (ctx != null) && (ctx.getId () != null) ) 127 { 130 136 if(isModified == null) 137 { 138 synchronizeState (ctx); 139 } 140 else 141 { 142 Boolean modified = (Boolean ) isModified.invoke (ctx.getInstance (), new Object [0]); 143 if (modified.booleanValue ()) 144 synchronizeState (ctx); 145 } 146 } 147 } 148 } 149 150 protected void synchronizeState (EnterpriseContext ctx) throws Exception 151 { 152 ((HAPersistentManager)container.getPersistenceManager ()).synchroSession ((StatefulSessionEnterpriseContext)ctx); 153 } 154 155 160 public void setContainer (Container container) 161 { 162 this.container = (StatefulSessionContainer)container; 163 } 164 165 public Container getContainer () 166 { 167 return container; 168 } 169 170 } 171 172 | Popular Tags |