1 23 24 package hero.util; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 28 import hero.interfaces.BnNodeHookLocal; 29 import hero.interfaces.BnNodeLocal; 30 import hero.interfaces.BnProjectLocal; 31 import hero.interfaces.BnProjectLocalHome; 32 import hero.interfaces.BnProjectUtil; 33 import hero.interfaces.UserSessionUtil; 34 import hero.util.values.BonitaHookValue; 35 import hero.util.values.BonitaNodeValue; 36 import hero.util.values.BonitaProjectValue; 37 38 import javax.management.MBeanServer ; 39 import javax.management.ObjectName ; 40 import javax.management.InstanceAlreadyExistsException ; 41 import javax.management.MBeanRegistrationException ; 42 import javax.management.NotCompliantMBeanException ; 43 import javax.management.MalformedObjectNameException ; 44 import javax.management.NotificationListener ; 45 import javax.management.Notification ; 46 import javax.naming.Context ; 47 import org.objectweb.jonas.service.ServiceException; 48 49 import org.objectweb.jonas.jmx.JmxService; 51 import org.objectweb.jonas.service.AbsServiceImpl; 52 import org.objectweb.jonas.service.ServiceManager; 53 54 public class TimerReceiver extends AbsServiceImpl implements TimerReceiverMBean, NotificationListener { 55 56 private MBeanServer mbeanServer = null; 57 public final static String SERVICE_NAME = "jonas:type=service,name=TimerReceiver"; 58 private static final UserSessionUtil EngineSessionUtil = null; 59 60 public void doInit(Context ctx) throws ServiceException { 61 63 try { 64 JmxService jmx = (JmxService) ServiceManager.getInstance().getJmxService(); 65 mbeanServer = jmx.getJmxServer(); 66 } catch (Exception e) { 67 throw new ServiceException("JMX Server is not started..."); 69 } 70 } 71 72 public void doStart() throws ServiceException { 73 try { 74 mbeanServer.registerMBean(this,new ObjectName (SERVICE_NAME)); 76 System.out.println("TimerReceiver :: Start Service"); 77 } catch (InstanceAlreadyExistsException iae) { 78 throw new ServiceException("Cannot start the TimerReceiver Service (Already Exists)" , iae); 79 } catch (MBeanRegistrationException mbre) { 80 throw new ServiceException("Cannot start the TimerReceiver Service (MBean registration error)" , mbre); 81 } catch (NotCompliantMBeanException ncmbe) { 82 throw new ServiceException("Cannot start the TimerReceiver Service (MBean Not compliant error)" , ncmbe); 83 } catch (MalformedObjectNameException mone) { 84 throw new ServiceException("Cannot start the TimerReceiver Service (ObjectName Malformed)" , mone); 85 } 86 } 87 88 public void handleNotification(Notification n, Object handback) { 89 BnProjectLocal mProject=null; 90 BonitaProjectValue model; 91 BonitaNodeValue node; 92 Collection hooks; 93 94 String type=(String )n.getType(); 95 String projectName=type.substring(type.indexOf(":")+1); 96 projectName = projectName.substring(0,projectName.indexOf(":")); 97 String nodeName=type.substring(0,type.indexOf(":")); 98 try{ 99 BnProjectLocalHome pHome = BnProjectUtil.getLocalHome(); 100 mProject=pHome.findByName(projectName); 101 102 }catch(Exception ple){ple.printStackTrace();} 103 104 try { 105 model = mProject.getModel(); 106 node = BonitaServiceValue.getNodeFromCache(model,nodeName); 107 108 109 if (nodeName.matches(".*_instance.*")) 110 nodeName=nodeName.substring(0,nodeName.indexOf("_instance")); 111 112 BonitaNodeValue nodeLocal; 113 nodeLocal = BonitaServiceValue.getNodeFromCache(model,nodeName); 114 115 hooks = nodeLocal.getHooks(); 116 for (Iterator i = hooks.iterator(); i.hasNext();) { 117 BonitaHookValue hk = (BonitaHookValue) i.next(); 118 if (hk.getEvent().equalsIgnoreCase(hero.interfaces.Constants.Nd.ONDEADLINE)) { 119 hero.hook.Hook h = hero.hook.Hook.make(hk.getName(), hero.interfaces.Constants.Nd.ONDEADLINE, hk.getType()); 120 } 122 } 123 124 }catch(HeroException hh){hh.printStackTrace();}; 125 } 126 127 public void doStop() throws ServiceException { 128 if (mbeanServer != null) { 129 try { 130 mbeanServer.unregisterMBean(new ObjectName (SERVICE_NAME)); 131 } catch (Exception e) { 132 throw new ServiceException("Cannot stop the TimerReceiver Service (JMX).", e); 133 } 134 } 135 System.out.println("TimerReceiver :: Stop Service"); 136 } 137 } 138 | Popular Tags |