1 25 26 package org.objectweb.sampleCluster2.ejb; 27 28 import java.util.Date ; 29 import java.util.Properties ; 30 31 import javax.ejb.CreateException ; 32 import javax.ejb.SessionBean ; 33 import javax.ejb.SessionContext ; 34 import javax.naming.InitialContext ; 35 import javax.naming.NamingException ; 36 37 import org.objectweb.jonas.common.JProp; 38 import org.objectweb.jonas.common.Log; 39 40 import org.objectweb.util.monolog.api.BasicLevel; 41 import org.objectweb.util.monolog.api.Logger; 42 43 47 public class MyEjb1SLR implements SessionBean { 48 49 52 private static final long serialVersionUID = 1L; 53 54 55 58 private static final int DIV = 10; 59 63 public void setSessionContext(SessionContext ctx) { 64 if (logger == null) { 65 logger = Log.getLogger("org.objectweb.jonas_tests"); 66 } 67 logger.log(BasicLevel.DEBUG, ""); 68 } 69 70 73 public void ejbRemove() { 74 logger.log(BasicLevel.DEBUG, ""); 75 } 76 77 80 public void ejbCreate() { 81 logger.log(BasicLevel.DEBUG, ""); 82 jonasInstanceName = "unknown"; 83 84 try { 85 JProp jp = JProp.getInstance(); 86 jonasInstanceName = jp.getValue("jonas.name"); 87 } catch (Exception e) { 88 logger.log(BasicLevel.FATAL, "Error while creating MyEjb1SLR : " + e.getMessage()); 89 } 90 91 logger.log(BasicLevel.DEBUG, "ejbCreate()->" + this.toString()); 92 } 93 94 97 public void ejbPassivate() { 98 logger.log(BasicLevel.DEBUG, ""); 99 } 100 101 104 public void ejbActivate() { 105 logger.log(BasicLevel.DEBUG, ""); 106 } 107 108 114 public String getProperty(String prop) { 115 String s = "unknown"; 116 try { 117 JProp jp = JProp.getInstance(); 118 s = jp.getValue(prop); 119 } catch (Exception e) { 120 logger.log(BasicLevel.FATAL, "Error while getProperty : " + e.getMessage()); 121 } 122 return s; 123 } 124 125 134 public Properties getInfoProps() { 135 updateStatistics(); 136 Properties p = new Properties (); 137 p.setProperty("EJB server", jonasInstanceName); 138 p.setProperty("EJB id", this.toString()); 139 p.setProperty("EJB total calls", (new Integer (allInstancesTotalCallsCount)).toString()); 140 p.setProperty("EJB server entity created", entityJonasInstanceName); 141 return p; 142 } 143 144 147 private void updateStatistics() { 148 allInstancesTotalCallsCount++; 149 150 if ((allInstancesTotalCallsCount % DIV) == 0) { 152 logger.log(BasicLevel.INFO, "Trying to create the entity"); 154 Date date = new Date (); 155 MyEntityLocal entity = createEntity(Long.toString(date.getTime())); 156 logger.log(BasicLevel.INFO, "Finished to create the entity"); 157 entityJonasInstanceName = entity.getJOnASName(); 158 } else { 159 entityJonasInstanceName = "No entity Bean created"; 160 } 161 162 logger.log(BasicLevel.INFO, "JOnAS=" + jonasInstanceName + " ; ejb=" + this.toString() + " ; total calls=" 163 + allInstancesTotalCallsCount + " ; entity created on=" + entityJonasInstanceName); 164 } 165 166 171 private MyEntityLocal createEntity(String valeur) { 172 InitialContext cntx; 173 MyEntityLocal result = null; 174 try { 175 cntx = new InitialContext (); 176 MyEntityLocalHome entityHome = (MyEntityLocalHome) cntx.lookup("MyEntityHome_L"); 177 result = entityHome.create(valeur); 178 } catch (NamingException e) { 179 logger.log(BasicLevel.FATAL, "Naming exception : " + e.getMessage()); 180 } catch (CreateException e) { 181 logger.log(BasicLevel.FATAL, "Create exception : " + e.getMessage()); 182 } 183 return result; 184 } 185 186 189 private static Logger logger = null; 190 191 192 196 private String entityJonasInstanceName = "unknown"; 197 198 202 private String jonasInstanceName = "unknown"; 203 204 208 private static int allInstancesTotalCallsCount = 0; 209 } 210 211 | Popular Tags |