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