List of usage examples for javax.management MBeanServerInvocationHandler newProxyInstance
public static <T> T newProxyInstance(MBeanServerConnection connection, ObjectName objectName, Class<T> interfaceClass, boolean notificationBroadcaster)
Return a proxy that implements the given interface by forwarding its methods through the given MBean server to the named MBean.
From source file:com.espertech.esper.example.servershellclient.ServerShellClientMain.java
public ServerShellClientMain() throws Exception { log.info("Loading properties"); Properties properties = new Properties(); InputStream propertiesIS = ServerShellClientMain.class.getClassLoader() .getResourceAsStream(ServerShellConstants.CONFIG_FILENAME); if (propertiesIS == null) { throw new RuntimeException( "Properties file '" + ServerShellConstants.CONFIG_FILENAME + "' not found in classpath"); }//from ww w . jav a 2 s .c om properties.load(propertiesIS); // Attached via JMX to running server log.info("Attach to server via JMX"); JMXServiceURL url = new JMXServiceURL(properties.getProperty(ServerShellConstants.MGMT_SERVICE_URL)); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mBeanName = new ObjectName(ServerShellConstants.MGMT_MBEAN_NAME); EPServiceProviderJMXMBean proxy = (EPServiceProviderJMXMBean) MBeanServerInvocationHandler .newProxyInstance(mbsc, mBeanName, EPServiceProviderJMXMBean.class, true); // Connect to JMS log.info("Connecting to JMS server"); String factory = properties.getProperty(ServerShellConstants.JMS_CONTEXT_FACTORY); String jmsurl = properties.getProperty(ServerShellConstants.JMS_PROVIDER_URL); String connFactoryName = properties.getProperty(ServerShellConstants.JMS_CONNECTION_FACTORY_NAME); String user = properties.getProperty(ServerShellConstants.JMS_USERNAME); String password = properties.getProperty(ServerShellConstants.JMS_PASSWORD); String destination = properties.getProperty(ServerShellConstants.JMS_INCOMING_DESTINATION); boolean isTopic = Boolean.parseBoolean(properties.getProperty(ServerShellConstants.JMS_IS_TOPIC)); JMSContext jmsCtx = JMSContextFactory.createContext(factory, jmsurl, connFactoryName, user, password, destination, isTopic); // Create statement via JMX log.info("Creating a statement via Java Management Extensions (JMX) MBean Proxy"); proxy.createEPL("select * from SampleEvent where duration > 9.9", "filterStatement", new ClientSideUpdateListener()); // Get producer jmsCtx.getConnection().start(); MessageProducer producer = jmsCtx.getSession().createProducer(jmsCtx.getDestination()); Random random = new Random(); String[] ipAddresses = { "127.0.1.0", "127.0.2.0", "127.0.3.0", "127.0.4.0" }; NumberFormat format = NumberFormat.getInstance(); // Send messages for (int i = 0; i < 1000; i++) { String ipAddress = ipAddresses[random.nextInt(ipAddresses.length)]; double duration = 10 * random.nextDouble(); String durationStr = format.format(duration); String payload = ipAddress + "," + durationStr; BytesMessage bytesMessage = jmsCtx.getSession().createBytesMessage(); bytesMessage.writeBytes(payload.getBytes()); bytesMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); producer.send(bytesMessage); if (i % 100 == 0) { log.info("Sent " + i + " messages"); } } // Create statement via JMX log.info("Destroing statement via Java Management Extensions (JMX) MBean Proxy"); proxy.destroy("filterStatement"); log.info("Shutting down JMS client connection"); jmsCtx.destroy(); log.info("Exiting"); System.exit(-1); }
From source file:com.rosy.bill.utils.jmx.JmxClientTemplate.java
/** * MBean?.//from w w w . j av a 2 s.c o m */ public <T> T createMBeanProxy(final String mbeanName, final Class<T> mBeanInterface) { Assert.hasText(mbeanName, "mbeanName?"); assertConnected(); ObjectName objectName = buildObjectName(mbeanName); return MBeanServerInvocationHandler.newProxyInstance(connection, objectName, mBeanInterface, false); }
From source file:com.flexive.shared.cache.impl.FxJBossExternalCacheProvider.java
/** * {@inheritDoc}// www . j a v a 2 s.co m */ @Override public void init() throws FxCacheException { if (cache != null) return; try { // first check if the cache MBean exists final ObjectName objectName = new ObjectName("jboss.cache:service=JNDITreeCache"); final Pair<MBeanServer, MBeanInfo> beanInfo = MBeanHelper.getMBeanInfo(objectName); // create wrapper MBean (cast necessary for java 1.5) final CacheJmxWrapperMBean wrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler .newProxyInstance(beanInfo.getFirst(), objectName, CacheJmxWrapperMBean.class, false); cache = new FxJBossTreeCacheMBeanWrapper(wrapper); evictChildren(""); // clean up possible leftovers from previous deployment LOG.trace(Fqn.class); } catch (Exception e) { throw new FxCacheException(e); } }
From source file:eu.itesla_project.online.tools.RunTDSimulationsMpiTool.java
@Override public void run(CommandLine line) throws Exception { OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault(); String host = line.getOptionValue(OnlineWorkflowCommand.HOST); String port = line.getOptionValue(OnlineWorkflowCommand.PORT); String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS); if (host != null) startconfig.setJmxHost(host);// w w w. j a va 2 s. c om if (port != null) startconfig.setJmxPort(Integer.valueOf(port)); if (threads != null) startconfig.setThreads(Integer.valueOf(threads)); String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map<String, String> jmxEnv = new HashMap<>(); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME); LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false); boolean emptyContingency = line.hasOption("empty-contingency"); Path caseFile = Paths.get(line.getOptionValue("case-file")); application.runTDSimulations(startconfig, caseFile.toString(), line.getOptionValue("contingencies"), Boolean.toString(emptyContingency), line.getOptionValue("output-folder")); }
From source file:net.tzolov.geode.jmx.JmxInfluxLoader.java
private GeodeDistributedSystem getDistributedSystemMXBean() { if (distributedSystemMXBean == null) { try {//from w ww . j a va2s. c om distributedSystemMXBean = MBeanServerInvocationHandler.newProxyInstance(jmxConnection, new ObjectName(GEM_FIRE_SERVICE_SYSTEM_TYPE_DISTRIBUTED), GeodeDistributedSystem.class, false); } catch (MalformedObjectNameException e) { log.error("", e); } } return distributedSystemMXBean; }
From source file:org.red5.server.tomcat.TomcatVHostLoader.java
/** * Initialization./*from www.ja v a 2 s. co m*/ */ @SuppressWarnings("cast") public void init() { log.info("Loading tomcat virtual host"); if (webappFolder != null) { //check for match with base webapp root if (webappFolder.equals(webappRoot)) { log.error("Web application root cannot be the same as base"); return; } } ClassLoader classloader = Thread.currentThread().getContextClassLoader(); //ensure we have a host if (host == null) { host = createHost(); } host.setParentClassLoader(classloader); String propertyPrefix = name; if (domain != null) { propertyPrefix += '_' + domain.replace('.', '_'); } log.debug("Generating name (for props) {}", propertyPrefix); System.setProperty(propertyPrefix + ".webapp.root", webappRoot); log.info("Virtual host root: {}", webappRoot); log.info("Virtual host context id: {}", defaultApplicationContextId); // Root applications directory File appDirBase = new File(webappRoot); // Subdirs of root apps dir File[] dirs = appDirBase.listFiles(new TomcatLoader.DirectoryFilter()); // Search for additional context files for (File dir : dirs) { String dirName = '/' + dir.getName(); // check to see if the directory is already mapped if (null == host.findChild(dirName)) { String webappContextDir = FileUtil.formatPath(appDirBase.getAbsolutePath(), dirName); Context ctx = null; if ("/root".equals(dirName) || "/root".equalsIgnoreCase(dirName)) { log.debug("Adding ROOT context"); ctx = addContext("/", webappContextDir); } else { log.debug("Adding context from directory scan: {}", dirName); ctx = addContext(dirName, webappContextDir); } log.debug("Context: {}", ctx); webappContextDir = null; } } appDirBase = null; dirs = null; // Dump context list if (log.isDebugEnabled()) { for (Container cont : host.findChildren()) { log.debug("Context child name: {}", cont.getName()); } } engine.addChild(host); // Start server try { log.info("Starting Tomcat virtual host"); //may not have to do this step for every host LoaderBase.setApplicationLoader(new TomcatApplicationLoader(embedded, host, applicationContext)); for (Container cont : host.findChildren()) { if (cont instanceof StandardContext) { StandardContext ctx = (StandardContext) cont; ServletContext servletContext = ctx.getServletContext(); log.debug("Context initialized: {}", servletContext.getContextPath()); //set the hosts id servletContext.setAttribute("red5.host.id", getHostId()); String prefix = servletContext.getRealPath("/"); log.debug("Path: {}", prefix); try { Loader cldr = ctx.getLoader(); log.debug("Loader type: {}", cldr.getClass().getName()); ClassLoader webClassLoader = cldr.getClassLoader(); log.debug("Webapp classloader: {}", webClassLoader); //create a spring web application context XmlWebApplicationContext appctx = new XmlWebApplicationContext(); appctx.setClassLoader(webClassLoader); appctx.setConfigLocations(new String[] { "/WEB-INF/red5-*.xml" }); //check for red5 context bean if (applicationContext.containsBean(defaultApplicationContextId)) { appctx.setParent( (ApplicationContext) applicationContext.getBean(defaultApplicationContextId)); } else { log.warn("{} bean was not found in context: {}", defaultApplicationContextId, applicationContext.getDisplayName()); //lookup context loader and attempt to get what we need from it if (applicationContext.containsBean("context.loader")) { ContextLoader contextLoader = (ContextLoader) applicationContext .getBean("context.loader"); appctx.setParent(contextLoader.getContext(defaultApplicationContextId)); } else { log.debug("Context loader was not found, trying JMX"); MBeanServer mbs = JMXFactory.getMBeanServer(); //get the ContextLoader from jmx ObjectName oName = JMXFactory.createObjectName("type", "ContextLoader"); ContextLoaderMBean proxy = null; if (mbs.isRegistered(oName)) { proxy = (ContextLoaderMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, oName, ContextLoaderMBean.class, true); log.debug("Context loader was found"); appctx.setParent(proxy.getContext(defaultApplicationContextId)); } else { log.warn("Context loader was not found"); } } } if (log.isDebugEnabled()) { if (appctx.getParent() != null) { log.debug("Parent application context: {}", appctx.getParent().getDisplayName()); } } // appctx.setServletContext(servletContext); //set the root webapp ctx attr on the each servlet context so spring can find it later servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appctx); appctx.refresh(); } catch (Throwable t) { log.error("Error setting up context: {}", servletContext.getContextPath(), t); if (log.isDebugEnabled()) { t.printStackTrace(); } } } } } catch (Exception e) { log.error("Error loading Tomcat virtual host", e); } }
From source file:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java
public void start() throws IOException { MBeanServer server = getMBeanServer(); if (exposeMBeansAsUPNP.booleanValue()) { try {/*from w w w . j a v a2s .c o m*/ ObjectName delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate"); NotificationEmitter emmiter = (NotificationEmitter) MBeanServerInvocationHandler .newProxyInstance(server, delegate, NotificationEmitter.class, false); // register for MBeans registration emmiter.addNotificationListener(this, null, this); } catch (Exception ex) { IOException ioEx = new IOException("UPNPConnector start error"); ioEx.initCause(ex); throw ioEx; } } if (exposeUPNPAsMBeans.booleanValue()) { int timeout = 2500; if (env.containsKey(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)) { timeout = ((Integer) env.get(EXPOSE_UPNP_DEVICES_AS_MBEANS_TIMEOUT)).intValue(); } try { discoveryBeanName = new ObjectName("UPNPLib discovery:name=Discovery MBean_" + this.hashCode()); UPNPDiscoveryMBean bean = new UPNPDiscovery(timeout, handleSSDPMessages.booleanValue(), true); server.registerMBean(bean, discoveryBeanName); } catch (Exception ex) { IOException ioEx = new IOException("Error occured during MBeans discovery"); ioEx.initCause(ex); throw ioEx; } } if (exposeExistingMBeansAsUPNP.booleanValue()) { int c = 0; Set objectInstances = super.getMBeanServer().queryNames(null, null); for (Iterator i = objectInstances.iterator(); i.hasNext();) { ObjectName name = (ObjectName) i.next(); MBeanServerNotification not = new MBeanServerNotification( MBeanServerNotification.REGISTRATION_NOTIFICATION, this, c++, name); handleNotification(not, this); } } }
From source file:eu.itesla_project.online.tools.RunForecastErrorsAnalysisMpiTool.java
@Override public void run(CommandLine line) throws Exception { OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault(); String host = line.getOptionValue(OnlineWorkflowCommand.HOST); String port = line.getOptionValue(OnlineWorkflowCommand.PORT); String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS); if (host != null) startconfig.setJmxHost(host);/*from w w w. ja v a 2 s.com*/ if (port != null) startconfig.setJmxPort(Integer.valueOf(port)); if (threads != null) startconfig.setThreads(Integer.valueOf(threads)); String analysisId = line.getOptionValue("analysis"); DateTime baseCaseDate = line.hasOption("base-case-date") ? DateTime.parse(line.getOptionValue("base-case-date")) : getDefaultParameters().getBaseCaseDate(); Interval histoInterval = line.hasOption("history-interval") ? Interval.parse(line.getOptionValue("history-interval")) : getDefaultParameters().getHistoInterval(); double ir = line.hasOption("ir") ? Double.parseDouble(line.getOptionValue("ir")) : getDefaultParameters().getIr(); int flagPQ = line.hasOption("flagPQ") ? Integer.parseInt(line.getOptionValue("flagPQ")) : getDefaultParameters().getFlagPQ(); int method = line.hasOption("method") ? Integer.parseInt(line.getOptionValue("method")) : getDefaultParameters().getMethod(); Integer nClusters = line.hasOption("nClusters") ? Integer.parseInt(line.getOptionValue("nClusters")) : getDefaultParameters().getnClusters(); double percentileHistorical = line.hasOption("percentileHistorical") ? Double.parseDouble(line.getOptionValue("percentileHistorical")) : getDefaultParameters().getPercentileHistorical(); Integer modalityGaussian = line.hasOption("modalityGaussian") ? Integer.parseInt(line.getOptionValue("modalityGaussian")) : getDefaultParameters().getModalityGaussian(); Integer outliers = line.hasOption("outliers") ? Integer.parseInt(line.getOptionValue("outliers")) : getDefaultParameters().getOutliers(); Integer conditionalSampling = line.hasOption("conditionalSampling") ? Integer.parseInt(line.getOptionValue("conditionalSampling")) : getDefaultParameters().getConditionalSampling(); Integer nSamples = line.hasOption("nSamples") ? Integer.parseInt(line.getOptionValue("nSamples")) : getDefaultParameters().getnSamples(); Set<Country> countries = line.hasOption("countries") ? Arrays.stream(line.getOptionValue("countries").split(",")).map(Country::valueOf).collect( Collectors.toSet()) : getDefaultParameters().getCountries(); CaseType caseType = line.hasOption("case-type") ? CaseType.valueOf(line.getOptionValue("case-type")) : getDefaultParameters().getCaseType(); ForecastErrorsAnalysisParameters parameters = new ForecastErrorsAnalysisParameters(baseCaseDate, histoInterval, analysisId, ir, flagPQ, method, nClusters, percentileHistorical, modalityGaussian, outliers, conditionalSampling, nSamples, countries, caseType); String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map<String, String> jmxEnv = new HashMap<>(); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME); LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false); String timeHorizonS = ""; if (line.hasOption("time-horizon")) { timeHorizonS = line.getOptionValue("time-horizon"); } application.runFeaAnalysis(startconfig, parameters, timeHorizonS); }
From source file:eu.itesla_project.online.tools.OnlineWorkflowTool.java
@Override public void run(CommandLine line) throws Exception { OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault(); String host = line.getOptionValue(OnlineWorkflowCommand.HOST); String port = line.getOptionValue(OnlineWorkflowCommand.PORT); String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS); if (host != null) startconfig.setJmxHost(host);//from w ww . j a va 2 s. c om if (port != null) startconfig.setJmxPort(Integer.valueOf(port)); if (threads != null) startconfig.setThreads(Integer.valueOf(threads)); Set<DateTime> baseCasesSet = null; OnlineWorkflowParameters params = OnlineWorkflowParameters.loadDefault(); boolean atLeastOneBaseCaseLineParam = line.hasOption(OnlineWorkflowCommand.CASE_TYPE) || line.hasOption(OnlineWorkflowCommand.COUNTRIES) || line.hasOption(OnlineWorkflowCommand.BASE_CASE) || line.hasOption(OnlineWorkflowCommand.BASECASES_INTERVAL); boolean allNeededBaseCaseLineParams = line.hasOption(OnlineWorkflowCommand.CASE_TYPE) && line.hasOption(OnlineWorkflowCommand.COUNTRIES) && (line.hasOption(OnlineWorkflowCommand.BASE_CASE) || line.hasOption(OnlineWorkflowCommand.BASECASES_INTERVAL)); if (line.hasOption(OnlineWorkflowCommand.CASE_FILE)) { if (atLeastOneBaseCaseLineParam) { showHelp("parameter " + OnlineWorkflowCommand.CASE_FILE + " cannot be used together with parameters: " + OnlineWorkflowCommand.CASE_TYPE + ", " + OnlineWorkflowCommand.COUNTRIES + ", " + OnlineWorkflowCommand.BASE_CASE + ", " + OnlineWorkflowCommand.BASECASES_INTERVAL); return; } params.setCaseFile(line.getOptionValue(OnlineWorkflowCommand.CASE_FILE)); } else { if (params.getCaseFile() != null) { if (atLeastOneBaseCaseLineParam) { if (!allNeededBaseCaseLineParams) { showHelp("to override default parameter " + OnlineWorkflowCommand.CASE_FILE + ", all these parameters must be specified: " + OnlineWorkflowCommand.CASE_TYPE + ", " + OnlineWorkflowCommand.COUNTRIES + ", " + OnlineWorkflowCommand.BASE_CASE + " or " + OnlineWorkflowCommand.BASECASES_INTERVAL); return; } params.setCaseFile(null); } } if (line.hasOption(OnlineWorkflowCommand.CASE_TYPE)) params.setCaseType(CaseType.valueOf(line.getOptionValue(OnlineWorkflowCommand.CASE_TYPE))); if (line.hasOption(OnlineWorkflowCommand.COUNTRIES)) { params.setCountries(Arrays.stream(line.getOptionValue(OnlineWorkflowCommand.COUNTRIES).split(",")) .map(Country::valueOf).collect(Collectors.toSet())); } if (line.hasOption(OnlineWorkflowCommand.BASECASES_INTERVAL)) { Interval basecasesInterval = Interval .parse(line.getOptionValue(OnlineWorkflowCommand.BASECASES_INTERVAL)); OnlineConfig oConfig = OnlineConfig.load(); CaseRepository caseRepo = oConfig.getCaseRepositoryFactoryClass().newInstance() .create(new LocalComputationManager()); baseCasesSet = caseRepo.dataAvailable(params.getCaseType(), params.getCountries(), basecasesInterval); System.out.println("Base cases available for interval " + basecasesInterval.toString()); baseCasesSet.forEach(x -> { System.out.println(" " + x); }); } if (baseCasesSet == null) { baseCasesSet = new HashSet<>(); String base = line.getOptionValue(OnlineWorkflowCommand.BASE_CASE); if (base != null) { baseCasesSet.add(DateTime.parse(base)); } else { baseCasesSet.add(params.getBaseCaseDate()); } } } String histo = line.getOptionValue(OnlineWorkflowCommand.HISTODB_INTERVAL); if (histo != null) params.setHistoInterval(Interval.parse(histo)); String states = line.getOptionValue(OnlineWorkflowCommand.STATES); if (states != null) params.setStates(Integer.parseInt(states)); String timeHorizon = line.getOptionValue(OnlineWorkflowCommand.TIME_HORIZON); if (timeHorizon != null) params.setTimeHorizon(TimeHorizon.fromName(timeHorizon)); String workflowid = line.getOptionValue(OnlineWorkflowCommand.WORKFLOW_ID); if (workflowid != null) params.setOfflineWorkflowId(workflowid); String feAnalysisId = line.getOptionValue(OnlineWorkflowCommand.FEANALYSIS_ID); if (feAnalysisId != null) params.setFeAnalysisId(feAnalysisId); String rulesPurity = line.getOptionValue(OnlineWorkflowCommand.RULES_PURITY); if (rulesPurity != null) params.setRulesPurityThreshold(Double.parseDouble(rulesPurity)); if (line.hasOption(OnlineWorkflowCommand.STORE_STATES)) params.setStoreStates(true); if (line.hasOption(OnlineWorkflowCommand.ANALYSE_BASECASE)) params.setAnalyseBasecase(true); if (line.hasOption(OnlineWorkflowCommand.VALIDATION)) { params.setValidation(true); params.setStoreStates(true); // if validation then store states params.setAnalyseBasecase(true); // if validation then analyze base case } Set<SecurityIndexType> securityIndexes = null; if (line.hasOption(OnlineWorkflowCommand.SECURITY_INDEXES)) { if (!"ALL".equals(line.getOptionValue(OnlineWorkflowCommand.SECURITY_INDEXES))) securityIndexes = Arrays .stream(line.getOptionValue(OnlineWorkflowCommand.SECURITY_INDEXES).split(",")) .map(SecurityIndexType::valueOf).collect(Collectors.toSet()); params.setSecurityIndexes(securityIndexes); } if (line.hasOption(OnlineWorkflowCommand.MERGE_OPTIMIZED)) params.setMergeOptimized(true); String limitReduction = line.getOptionValue(OnlineWorkflowCommand.LIMIT_REDUCTION); if (limitReduction != null) params.setLimitReduction(Float.parseFloat(limitReduction)); if (line.hasOption(OnlineWorkflowCommand.HANDLE_VIOLATION_IN_N)) { params.setHandleViolationsInN(true); params.setAnalyseBasecase(true); // if I need to handle violations in N, I need to analyze base case } String constraintMargin = line.getOptionValue(OnlineWorkflowCommand.CONSTRAINT_MARGIN); if (constraintMargin != null) params.setConstraintMargin(Float.parseFloat(constraintMargin)); String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map<String, String> jmxEnv = new HashMap<>(); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME); LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false); if (line.hasOption(OnlineWorkflowCommand.START_CMD)) { if (params.getCaseFile() != null) { System.out.println("starting Online Workflow, caseFile " + params.getCaseFile()); String workflowId = application.startWorkflow(startconfig, params); System.out.println("workflowId=" + workflowId); } else { for (DateTime basecase : baseCasesSet) { params.setBaseCaseDate(basecase); System.out.println("starting Online Workflow, basecase " + basecase.toString()); String workflowId = application.startWorkflow(startconfig, params); System.out.println("workflowId=" + workflowId); } } } else if (line.hasOption(OnlineWorkflowCommand.SHUTDOWN_CMD)) { application.shutdown(); } else { showHelp(""); } }
From source file:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java
public void stop() throws IOException { MBeanServer server = getMBeanServer(); IOException error = null;//from w w w.ja va2 s. c om if (exposeMBeansAsUPNP.booleanValue()) { try { ObjectName delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate"); NotificationEmitter emmiter = (NotificationEmitter) MBeanServerInvocationHandler .newProxyInstance(server, delegate, NotificationEmitter.class, false); emmiter.removeNotificationListener(this, null, this); } catch (Exception ex) { // MX4J throws an unexpected ListenerNotFoundException with jre 1.5.06.. works nice with sun JMX impl if (!(ex instanceof ListenerNotFoundException)) { IOException ioEx = new IOException("UPNPConnector stop error"); ioEx.initCause(ex); error = ioEx; } } synchronized (STOP_PROCESS) { // now stop all the remaining Devices for (Iterator i = registeredMBeans.values().iterator(); i.hasNext();) { UPNPMBeanDevice dv = (UPNPMBeanDevice) i.next(); try { dv.stop(); } catch (IOException ex) { log.error("Error during UPNPMBean device stop", ex); } } registeredMBeans.clear(); } } if (exposeUPNPAsMBeans.booleanValue()) { try { server.unregisterMBean(discoveryBeanName); } catch (Exception ex) { IOException ioEx = new IOException("Error occured during MBeans discovery"); ioEx.initCause(ex); throw ioEx; } } if (error != null) { throw error; } }