1 package hero.util; 2 3 31 32 import hero.interfaces.BnProjectLocal; 33 import hero.interfaces.BnProjectLocalHome; 34 import hero.interfaces.BnProjectConfigLocal; 35 36 import java.util.Collection ; 37 import java.util.Iterator ; 38 39 import javax.ejb.FinderException ; 40 import javax.management.MBeanServer ; 41 import javax.management.ObjectName ; 42 import javax.management.InstanceAlreadyExistsException ; 43 import javax.management.MBeanRegistrationException ; 44 import javax.management.NotCompliantMBeanException ; 45 import javax.management.MalformedObjectNameException ; 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 BonitaConfigService extends AbsServiceImpl implements BonitaConfigServiceMBean{ 55 56 private MBeanServer mbeanServer = null; 57 public final static String SERVICE_NAME = "jonas:type=service,name=BonitaConfigService"; 58 59 public void doInit(Context ctx) throws ServiceException { 60 try { 62 JmxService jmx = (JmxService) ServiceManager.getInstance().getJmxService(); 63 mbeanServer = jmx.getJmxServer(); 64 } catch (Exception e) { 65 throw new ServiceException("JMX Server is not started..."); 67 } 68 } 69 70 public void doStart() throws ServiceException { 71 try { 72 mbeanServer.registerMBean(this,new ObjectName (SERVICE_NAME)); 73 System.out.println("BonitaConfigService :: Start Service"); 74 } catch (InstanceAlreadyExistsException iae) { 75 throw new ServiceException("Cannot start the BonitaConfigService (Already Exists)" , iae); 76 } catch (MBeanRegistrationException mbre) { 77 throw new ServiceException("Cannot start the BonitaConfigService (MBean registration error)" , mbre); 78 } catch (NotCompliantMBeanException ncmbe) { 79 throw new ServiceException("Cannot start the BonitaConfigService (MBean Not compliant error)" , ncmbe); 80 } catch (MalformedObjectNameException mone) { 81 throw new ServiceException("Cannot start the BonitaConfigService (ObjectName Malformed)" , mone); 82 } 83 } 84 85 public void doStop() throws ServiceException { 86 if (mbeanServer != null) { 87 try { 88 mbeanServer.unregisterMBean(new ObjectName (SERVICE_NAME)); 89 } catch (Exception e) { 90 throw new ServiceException("Cannot stop the BonitaConfigService (JMX).", e); 91 } 92 } 93 System.out.println("BonitaConfigService :: Stop Service"); 94 } 95 96 public boolean getProcessJMS(String projectName) throws ServiceException { 97 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 98 return(pc.getJMS()); 99 } 100 101 public boolean getProcessLog(String projectName) throws ServiceException { 102 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 103 return(pc.getLog()); 104 105 } 106 107 public boolean getProcessTrace(String projectName) throws ServiceException { 108 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 109 return(pc.getTrace()); 110 } 111 112 public String getProcessLogLevel(String projectName) throws ServiceException { 113 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 114 return(pc.getLogLevel()); 115 } 116 117 public String getProcessTraceLevel(String projectName) throws ServiceException { 118 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 119 return(pc.getTraceLevel()); 120 } 121 122 public String getProcessHistoric(String projectName) throws ServiceException { 123 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 124 return(pc.getHistoric()); 125 } 126 127 public void setProcessJMS(String projectName, boolean value) throws ServiceException { 128 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 129 pc.setJMS(value); 130 } 131 132 public void setProcessLog(String projectName, boolean value) throws ServiceException { 133 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 134 pc.setLog(value); 135 } 136 137 public void setProcessTrace(String projectName, boolean value) throws ServiceException { 138 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 139 pc.setTrace(value); 140 } 141 142 public void setProcessTraceLevel(String projectName, String value) throws ServiceException { 143 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 144 pc.setTraceLevel(value); 145 } 146 147 public void setProcessLogLevel(String projectName, String value) throws ServiceException { 148 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 149 pc.setLogLevel(value); 150 } 151 152 public void setProcessHistoric(String projectName, String value) throws ServiceException { 153 BnProjectConfigLocal pc = this.getProjectConfig(projectName); 154 pc.setHistoric(value); 155 } 156 157 public void updateJMS(boolean value) throws ServiceException { 158 Collection projects = this.getProjects(); 159 Iterator prjs = projects.iterator(); 160 while (prjs.hasNext()) { 161 BnProjectLocal pj = (BnProjectLocal) prjs.next(); 162 BnProjectConfigLocal pc = pj.getBnProjectConfig(); 163 pc.setJMS(value); 164 } 165 } 166 167 public void updateLog(boolean value) throws ServiceException { 168 Collection projects = this.getProjects(); 169 Iterator prjs = projects.iterator(); 170 while (prjs.hasNext()) { 171 BnProjectLocal pj = (BnProjectLocal) prjs.next(); 172 BnProjectConfigLocal pc = pj.getBnProjectConfig(); 173 pc.setLog(value); 174 } 175 176 } 177 178 public void updateTrace(boolean value) throws ServiceException { 179 Collection projects = this.getProjects(); 180 Iterator prjs = projects.iterator(); 181 while (prjs.hasNext()) { 182 BnProjectLocal pj = (BnProjectLocal) prjs.next(); 183 BnProjectConfigLocal pc = pj.getBnProjectConfig(); 184 pc.setTrace(value); 185 } 186 187 } 188 189 public void updateLogLevel(String value) throws ServiceException { 190 Collection projects = this.getProjects(); 191 Iterator prjs = projects.iterator(); 192 while (prjs.hasNext()) { 193 BnProjectLocal pj = (BnProjectLocal) prjs.next(); 194 BnProjectConfigLocal pc = pj.getBnProjectConfig(); 195 pc.setLogLevel(value); 196 } 197 } 198 199 public void updateTraceLevel(String value) throws ServiceException { 200 Collection projects = this.getProjects(); 201 Iterator prjs = projects.iterator(); 202 while (prjs.hasNext()) { 203 BnProjectLocal pj = (BnProjectLocal) prjs.next(); 204 BnProjectConfigLocal pc = pj.getBnProjectConfig(); 205 pc.setTraceLevel(value); 206 } 207 } 208 209 public void updateHistoric(String value) throws ServiceException { 210 Collection projects = this.getProjects(); 211 Iterator prjs = projects.iterator(); 212 while (prjs.hasNext()) { 213 BnProjectLocal pj = (BnProjectLocal) prjs.next(); 214 BnProjectConfigLocal pc = pj.getBnProjectConfig(); 215 pc.setHistoric(value); 216 } 217 } 218 219 private BnProjectConfigLocal getProjectConfig(String projectName) throws ServiceException{ 220 BnProjectLocalHome phome = null; 221 BnProjectLocal plocal = null; 222 try { 223 phome = hero.interfaces.BnProjectUtil.getLocalHome(); 224 plocal = phome.findByName(projectName); 225 return(plocal.getBnProjectConfig()); 226 } catch (javax.naming.NamingException ne) { 227 throw new ServiceException(ne.getMessage()); 228 } catch (FinderException fie) { 229 throw new ServiceException(fie.getMessage()); 230 } 231 } 232 233 private Collection getProjects() throws ServiceException{ 234 BnProjectLocalHome phome = null; 235 BnProjectLocal plocal = null; 236 try { 237 phome = hero.interfaces.BnProjectUtil.getLocalHome(); 238 Collection projects = phome.findAll(); 239 return projects; 240 } catch (javax.naming.NamingException ne) { 241 throw new ServiceException(ne.getMessage()); 242 } catch (FinderException fie) { 243 throw new ServiceException(fie.getMessage()); 244 } 245 } 246 } 247 | Popular Tags |