1 22 package org.jboss.ejb3.test.clusteredsession; 23 24 import javax.persistence.PersistenceContext; 25 import javax.persistence.PersistenceContextType; 26 import javax.persistence.EntityManager; 27 import javax.annotation.PreDestroy; 28 import javax.ejb.Stateful ; 29 import javax.ejb.PrePassivate ; 30 import javax.ejb.PostActivate ; 31 32 import org.jboss.annotation.ejb.cache.simple.CacheConfig; 33 import org.jboss.annotation.ejb.Clustered; 34 35 41 @Stateful 42 @Clustered 43 @CacheConfig(maxSize = 1000, idleTimeoutSeconds = 2) 44 public class ContainedBean implements Contained 45 { 46 @PersistenceContext(type= PersistenceContextType.EXTENDED) EntityManager em; 47 48 Customer customer; 49 50 public Customer find(long id) 51 { 52 return em.find(Customer.class, id); 53 } 54 55 public void setCustomer(long id) 56 { 57 customer = find(id); 58 } 59 60 public Customer getCustomer() 61 { 62 return customer; 63 } 64 65 public void updateCustomer() 66 { 67 customer.setName("contained modified"); 68 } 69 70 public boolean isActivated() 71 { 72 return activated; 73 } 74 75 public static boolean destroyed = false; 76 public static boolean passivated = false; 77 public static boolean activate = false; 78 private boolean activated = false; 79 80 @PrePassivate 81 public void passivate() 82 { 83 passivated = true; 84 } 85 86 @PostActivate 87 public void activate() 88 { 89 System.out.println("*********** ACTIVATED *****************"); 90 if (activated) throw new RuntimeException ("ACTIVATED TWICE"); 91 activated = true; 92 if (activate) throw new RuntimeException ("ACTIVATED TWICE IN TWO DIFFERENT INSTANCES"); 93 activate = true; 94 95 } 96 97 @PreDestroy 98 public void destroy() 99 { 100 destroyed = true; 101 } 102 } 103 | Popular Tags |