1 51 52 package org.objectweb.jass.as.jboss; 53 54 import javax.naming.Context ; 55 import javax.naming.InitialContext ; 56 import javax.naming.Reference ; 57 58 import org.apache.log4j.Logger; 59 import org.jboss.system.ServiceMBeanSupport; 60 import org.objectweb.jass.as.ActivityIdGenerator; 61 import org.objectweb.jass.as.ActivityService; 62 63 70 public class JBOSSActivityService 71 extends ServiceMBeanSupport 72 implements JBOSSActivityServiceMBean { 73 74 private static Logger log = Logger.getLogger(JBOSSActivityService.class); 75 76 78 public static final String UA_JNDI_NAME = "UserActivity"; 80 public static final String AM_JNDI_NAME = "ActivityManager"; 81 82 84 87 public void startService() throws Exception { 88 89 Reference uaRef = 91 new Reference ( 92 "org.objectweb.jass.as.ActivityService", 93 "org.objectweb.jass.as.UserActivityObjectFactory", 94 null); 95 96 Reference amRef = 97 new Reference ( 98 "org.objectweb.jass.as.ActivityService", 99 "org.objectweb.jass.as.ActivityManagerObjectFactory", 100 null); 101 102 Context ctx = new InitialContext (); 103 104 log.info("Looking for an Activity Id generator..."); 107 ActivityIdGenerator activityIdGenerator = 108 (ActivityIdGenerator) ctx.lookup("ActivityIdGeneratorService"); 109 log.info("A reference to the Activity Id Generator acquired!!!"); 110 111 log.info("Setting generator in the Activity Service implementation..."); 112 ActivityService.setActivityIdGenerator(activityIdGenerator); 113 log.info("Activity Id Generator established as default generator!!!"); 114 115 log.info("Binding UserActivity Service and ActivityManager Services"); 116 ctx.bind(UA_JNDI_NAME, uaRef); 117 ctx.bind(AM_JNDI_NAME, amRef); 118 log.info("Bindings done!!!"); 119 } 120 121 124 public void stopService() { 125 try { 126 Context ctx = new InitialContext (); 127 ctx.unbind(UA_JNDI_NAME); 128 ctx.unbind(AM_JNDI_NAME); 129 } catch (Exception e) { 130 log.error("Failed to unbind", e); 131 } 132 } 133 134 136 142 public int getInstances() { 143 return ActivityService.getInstances(); 144 } 145 146 149 public int numberOfActivities() { 150 return 0; 151 } 152 153 } 154 | Popular Tags |