1 7 8 package org.jboss.ejb3.test.clusteredsession.nested; 9 10 import org.jboss.annotation.ejb.Clustered; 11 import org.jboss.annotation.ejb.cache.tree.CacheConfig; 12 import org.jboss.logging.Logger; 13 import org.jboss.system.server.ServerConfig; 14 import org.jboss.ejb3.test.clusteredsession.ExplicitFailoverInterceptor; 15 import org.jboss.ejb3.test.clusteredsession.NodeAnswer; 16 import org.jboss.ejb3.test.clusteredsession.ClusteredStatelessRemote; 17 18 import javax.interceptor.Interceptors; 19 import javax.annotation.PostConstruct; 20 import javax.ejb.EJB ; 21 import javax.ejb.Stateful ; 22 import javax.ejb.Remote ; 23 import javax.ejb.PostActivate ; 24 import javax.ejb.PrePassivate ; 25 import javax.ejb.Remove ; 26 import javax.ejb.EJBException ; 27 import java.rmi.dgc.VMID ; 28 29 35 @Stateful (name="testParentStateful") 36 @Clustered 37 @Interceptors({ExplicitFailoverInterceptor.class}) 39 @CacheConfig(maxSize=1000, idleTimeoutSeconds=3) @Remote(ParentStatefulRemote.class) 41 public class ParentStatefulBean implements java.io.Serializable , ParentStatefulRemote 42 { 43 private static Logger log = Logger.getLogger(ParentStatefulBean.class); 44 private int counter = 0; 45 private String state; 46 public transient VMID myId = null; 47 public String name; 48 49 @EJB 50 private NestedStateful nested; 51 52 @EJB 53 private ClusteredStatelessRemote slsb; 54 55 public int increment() 56 { 57 counter = nested.increment(); 58 59 log.debug("INCREMENT - parent counter: " + counter); 60 return counter; 61 } 62 63 public String getHostAddress() 64 { 65 return System.getProperty(ServerConfig.SERVER_BIND_ADDRESS); 66 } 67 68 public static int postActivateCalled = 0; 69 public static int prePassivateCalled = 0; 70 71 75 public void longRunning() throws Exception 76 { 77 log.debug("+++ longRunning() enter "); 78 Thread.sleep(10000); 79 log.debug("+++ longRunning() leave "); 80 } 81 82 public int getPostActivate() 83 { 84 return ParentStatefulBean.postActivateCalled; 85 } 86 87 public int getPrePassivate() 88 { 89 return ParentStatefulBean.prePassivateCalled; 90 } 91 92 public int getNestedPostActivate() 93 { 94 return NestedStatefulBean.postActivateCalled; 95 } 96 97 public int getNestedPrePassivate() 98 { 99 return NestedStatefulBean.prePassivateCalled; 100 } 101 102 public void setState(String state) 103 { 104 this.state = state; 105 } 106 107 public String getState() 108 { 109 log.debug("getState(): entering ..."); 110 return this.state; 111 } 112 113 public NodeAnswer getStatelessState() { 114 return slsb.getNodeState(); 115 } 116 117 public void reset() 118 { 119 state = null; 120 counter = 0; 121 ParentStatefulBean.postActivateCalled = 0; 122 ParentStatefulBean.prePassivateCalled = 0; 123 } 124 125 public void resetActivationCounter() 126 { 127 ParentStatefulBean.postActivateCalled = 0; 128 ParentStatefulBean.prePassivateCalled = 0; 129 NestedStatefulBean.postActivateCalled = 0; 130 NestedStatefulBean.prePassivateCalled = 0; 131 } 132 133 @PostActivate 134 public void postActivate() 135 { 136 ++ParentStatefulBean.postActivateCalled; 137 if (this.myId == null) 138 { 139 this.myId = new VMID (); 141 } 142 log.debug("Activate. My ID: " + this.myId + " name: " + this.name); 143 } 144 145 @PrePassivate 146 public void prePassivate() 147 { 148 ++ParentStatefulBean.prePassivateCalled; 149 log.debug("Passivate. My ID: " + this.myId + " name: " + this.name); 150 } 151 152 @Remove 153 public void remove() 154 { 155 } 156 157 @PostConstruct 158 public void ejbCreate() 159 { 160 this.myId = new VMID (); 161 log.debug("My ID: " + this.myId); 162 } 163 164 166 public NodeAnswer getNodeState() 167 { 168 if (this.myId == null) 169 { 170 this.myId = new VMID (); 172 } 173 174 NodeAnswer state = new NodeAnswer(this.myId, this.name); 175 log.debug("getNodeState, " + state); 176 return state; 177 } 178 179 public void setName(String name) 180 { 181 this.name = name; 182 log.debug("Name set to " + name); 183 } 184 185 public void setNameOnlyOnNode(String name, VMID node) 186 { 187 if (node.equals(this.myId)) 188 this.setName(name); 189 else 190 throw new EJBException ("Trying to assign value on node " + this.myId + " but this node expected: " + node); 191 } 192 193 public void setUpFailover(String failover) { 194 log.debug("Setting up failover property: " +failover); 196 System.setProperty ("JBossCluster-DoFail", failover); 197 } 198 } 199 | Popular Tags |