Java Code Examples for javax.management.MBeanServer

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project jafka, under directory /src/main/java/com/sohu/jafka/utils/.

Source file: Utils.java

  19 
vote

/** 
 * Unregister the mbean with the given name, if there is one registered
 * @param name The mbean name to unregister
 * @see #registerMBean(Object,String)
 */
private static void unregisterMBean(String name){
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  try {
synchronized (mbs) {
      ObjectName objName=new ObjectName(name);
      if (mbs.isRegistered(objName)) {
        mbs.unregisterMBean(objName);
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 2

From project nuxeo-jsf, under directory /nuxeo-platform-webapp-base/src/main/java/org/nuxeo/ecm/webapp/seam/.

Source file: NuxeoSeamFlusher.java

  19 
vote

protected void invalidateWebSessions() throws IOException, MalformedObjectNameException {
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  for (  ObjectInstance oi : mbs.queryMBeans(new ObjectName("Catalina:type=Manager,path=/nuxeo,host=*"),null)) {
    WebSessionFlusher flusher=JMX.newMBeanProxy(mbs,oi.getObjectName(),WebSessionFlusher.class);
    StringTokenizer tokenizer=new StringTokenizer(flusher.listSessionIds()," ");
    while (tokenizer.hasMoreTokens()) {
      String id=tokenizer.nextToken();
      flusher.expireSession(id);
    }
  }
}
 

Example 3

From project nuxeo-tycho-osgi, under directory /nuxeo-runtime/nuxeo-runtime-management/src/main/java/org/nuxeo/runtime/management/.

Source file: ServerLocatorService.java

  19 
vote

protected void doRegisterLocator(ServerLocatorDescriptor descriptor){
  MBeanServer server=descriptor.isExisting ? doFindServer(descriptor.domainName) : doCreateServer(descriptor);
  servers.put(descriptor.domainName,server);
  if (descriptor.isDefault) {
    defaultServer=server;
  }
}
 

Example 4

From project advanced, under directory /server-advanced/src/main/java/org/neo4j/server/advanced/modules/.

Source file: JMXManagementModule.java

  18 
vote

@Override public void start(StringLogger logger){
  try {
    serverManagement=new ServerManagement(server);
    MBeanServer beanServer=ManagementFactory.getPlatformMBeanServer();
    beanServer.registerMBean(serverManagement,createObjectName());
  }
 catch (  Exception e) {
    throw new RuntimeException("Unable to initialize jmx management, see nested exception.",e);
  }
}
 

Example 5

From project airlift, under directory /jmx/src/main/java/io/airlift/jmx/.

Source file: JmxInspector.java

  18 
vote

@Inject public JmxInspector(Injector injector) throws Exception {
  MBeanServer mBeanServer=ManagementFactory.getPlatformMBeanServer();
  Set<ObjectInstance> instances=mBeanServer.queryMBeans(null,null);
  Multimap<String,String> nameMap=ArrayListMultimap.create();
  for (  ObjectInstance i : instances) {
    nameMap.put(i.getClassName(),i.getObjectName().getCanonicalName());
  }
  ImmutableSortedSet.Builder<InspectorRecord> builder=ImmutableSortedSet.naturalOrder();
  GuiceInjectorIterator injectorIterator=new GuiceInjectorIterator(injector);
  for (  Class<?> clazz : injectorIterator) {
    addConfig(nameMap,clazz,builder);
  }
  inspectorRecords=builder.build();
}
 

Example 6

From project arquillian-container-osgi, under directory /bundle/src/main/java/org/jboss/arquillian/osgi/.

Source file: ArquillianBundleActivator.java

  18 
vote

private MBeanServer getMBeanServer(BundleContext context){
  ServiceReference sref=context.getServiceReference(MBeanServer.class.getName());
  if (sref != null) {
    MBeanServer mbeanServer=(MBeanServer)context.getService(sref);
    log.fine("Found MBeanServer fom service: " + mbeanServer.getDefaultDomain());
    return mbeanServer;
  }
  return findOrCreateMBeanServer();
}
 

Example 7

From project arquillian_deprecated, under directory /protocols/jmx/src/main/java/org/jboss/arquillian/protocol/jmx/.

Source file: JMXMethodExecutor.java

  18 
vote

private MBeanServer findOrCreateMBeanServer(){
  MBeanServer mbeanServer=null;
  ArrayList<MBeanServer> serverArr=MBeanServerFactory.findMBeanServer(null);
  if (serverArr.size() > 1)   log.warn("Multiple MBeanServer instances: " + serverArr);
  if (serverArr.size() > 0) {
    mbeanServer=serverArr.get(0);
    log.debug("Found MBeanServer: " + mbeanServer.getDefaultDomain());
  }
  if (mbeanServer == null) {
    log.debug("No MBeanServer, create one ...");
    mbeanServer=MBeanServerFactory.createMBeanServer();
  }
  return mbeanServer;
}
 

Example 8

From project bam, under directory /modules/active-queries/active-collection-jee/src/main/java/org/overlord/bam/active/collection/jee/.

Source file: ACManagement.java

  18 
vote

/** 
 * The initialize method.
 */
@PostConstruct public void init(){
  LOG.info("Register the ACManagement MBean: " + _acManager);
  try {
    MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
    ObjectName objname=new ObjectName(OBJECT_NAME_DOMAIN + OBJECT_NAME_MANAGER);
    mbs.registerMBean(this,objname);
  }
 catch (  Exception e) {
    LOG.log(Level.SEVERE,java.util.PropertyResourceBundle.getBundle("active-collection-jee.Messages").getString("ACTIVE-COLLECTION-JEE-1"),e);
  }
  _acManager.addActiveCollectionListener(this);
}
 

Example 9

From project bonecp, under directory /bonecp/src/test/java/com/jolbox/bonecp/.

Source file: TestBoneCP.java

  18 
vote

/** 
 * JMX setup test
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws InstanceAlreadyExistsException
 * @throws MBeanRegistrationException
 * @throws NotCompliantMBeanException
 */
@Test public void testJMX() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
  MBeanServer mockMbs=EasyMock.createNiceMock(MBeanServer.class);
  Field field=testClass.getClass().getDeclaredField("mbs");
  field.setAccessible(true);
  field.set(testClass,mockMbs);
  expect(mockConfig.getPoolName()).andReturn(null).anyTimes();
  ObjectInstance mockInstance=createNiceMock(ObjectInstance.class);
  expect(mockMbs.isRegistered((ObjectName)anyObject())).andReturn(false).anyTimes();
  expect(mockMbs.registerMBean(anyObject(),(ObjectName)anyObject())).andReturn(mockInstance).once().andThrow(new InstanceAlreadyExistsException()).once();
  replay(mockMbs,mockInstance,mockConfig);
  testClass.registerUnregisterJMX(true);
  verify(mockMbs);
}
 

Example 10

From project byteman, under directory /sample/src/org/jboss/byteman/sample/helper/.

Source file: ThreadHistoryMonitorHelper.java

  18 
vote

/** 
 * Register the INSTANCE as an mbean under the given name.
 * @param name - the object name string to register the INSTANCE under
 */
public void registerHelperMBean(String name){
synchronized (createMap) {
    MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
    try {
      ObjectName oname=new ObjectName(name);
      if (mbs.isRegistered(oname) == false)       mbs.registerMBean(INSTANCE,oname);
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
}
 

Example 11

From project camelpe, under directory /examples/loan-broker-jboss7/src/main/java/net/camelpe/examples/jboss7/loanbroker/queue/.

Source file: JBoss7CamelContextConfiguration.java

  18 
vote

@PostConstruct public void createQueues() throws Exception {
  this.log.info("Creating queues ...");
  final MBeanServer mbeanServer=ManagementFactory.getPlatformMBeanServer();
  this.log.info("Found PlatformMBeanServer [{}]",mbeanServer);
  this.log.info("JMX Domains: {}",Arrays.toString(mbeanServer.getDomains()));
  for (  final JmsResources.QueueDefinition queueDef : JmsResources.loanBrokerQueues()) {
    mbeanServer.invoke(new ObjectName("org.hornetq:module=JMS,type=Server"),"createQueue",new Object[]{queueDef.getName(),queueDef.getBinding()},new String[]{"java.lang.String","java.lang.String"});
    this.log.info("Created queue [{}]",queueDef);
  }
}
 

Example 12

From project Carolina-Digital-Repository, under directory /fcrepo-irods-storage/src/main/java/fedorax/server/module/storage/.

Source file: IrodsExternalContentManager.java

  18 
vote

private MBeanServer getMBeanServer(){
  MBeanServer mbserver=null;
  ArrayList mbservers=MBeanServerFactory.findMBeanServer(null);
  if (mbservers.size() > 0) {
    mbserver=(MBeanServer)mbservers.get(0);
  }
  if (mbserver != null) {
    System.out.println("Found our MBean server");
  }
 else {
    mbserver=MBeanServerFactory.createMBeanServer();
  }
  return mbserver;
}
 

Example 13

From project cipango, under directory /cipango-console/src/main/java/org/cipango/console/.

Source file: JmxConnection.java

  18 
vote

@Override protected void initJmxConnection(){
  List<MBeanServer> l=MBeanServerFactory.findMBeanServer(null);
  Iterator<MBeanServer> it=l.iterator();
  while (it.hasNext()) {
    MBeanServer server=it.next();
    for (int j=0; j < server.getDomains().length; j++) {
      if (server.isRegistered(JettyManager.SERVER)) {
        _mbsc=server;
        break;
      }
    }
  }
  _logger.debug("Use MBeanServerConnection {}",_mbsc,null);
}
 

Example 14

From project clustermeister, under directory /node/src/main/java/com/github/nethad/clustermeister/node/.

Source file: ClustermeisterNodeLifeCycleListener.java

  18 
vote

/** 
 * Shuts down or restarts this node.
 * @param restart true to restart the node, false to just shut down.
 */
protected void shutdownOrRestartNode(boolean restart){
  String method=restart ? "restart" : "shutdown";
  logger.info("Node {} requested.",method);
  final MBeanServer platformMBeanServer=ManagementFactory.getPlatformMBeanServer();
  ObjectName nodeAdminName=MBeanUtils.objectNameFor(logger,JPPFNodeAdminMBean.MBEAN_NAME);
  MBeanUtils.invoke(logger,platformMBeanServer,nodeAdminName,method);
}
 

Example 15

From project components-ness-config, under directory /src/main/java/com/nesscomputing/config/.

Source file: ConfigJmxExporter.java

  18 
vote

synchronized void export(Class<?> realClass,Object configBean){
  MBeanServer server=this.server;
  if (server == null) {
    delayedBeanExports.add(Maps.immutableEntry(realClass,configBean));
    return;
  }
  try {
    server.registerMBean(new ConfigMagicDynamicMBean(realClass.getName(),configBean),new ObjectName(munge(realClass.getName())));
  }
 catch (  Exception e) {
    LOG.error(e,"Unable to export config bean %s",configBean.getClass().getName());
  }
}
 

Example 16

From project dawn-workflow, under directory /org.dawb.workbench.jmx/src/org/dawb/workbench/jmx/.

Source file: RemoteWorkbenchAgent.java

  18 
vote

public void stop() throws Exception {
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  if (mbs.getObjectInstance(REMOTE_WORKBENCH) != null) {
    mbs.unregisterMBean(REMOTE_WORKBENCH);
    logger.debug("Workbench service stopped on " + serverUrl);
  }
  final Registry reg=LocateRegistry.getRegistry(getCurrentPort());
  if (reg.lookup("workbench") != null) {
    reg.unbind("workbench");
  }
}
 

Example 17

From project dozer, under directory /core/src/main/java/org/dozer/jmx/.

Source file: JMXPlatformImpl.java

  18 
vote

private void register(String name,Object bean,ObjectName mbeanObjectName) throws MBeanRegistrationException, NotCompliantMBeanException {
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  try {
    mbs.registerMBean(bean,mbeanObjectName);
    log.info("Dozer JMX MBean [" + name + "] auto registered with the Platform MBean Server");
  }
 catch (  InstanceAlreadyExistsException e) {
    log.info("JMX MBean instance exists, unable to overwrite [{}].",name);
  }
}
 

Example 18

From project gemini.web.gemini-web-container, under directory /org.eclipse.gemini.web.tomcat/src/test/java/org/eclipse/gemini/web/tomcat/internal/.

Source file: TomcatMBeanManagerTests.java

  18 
vote

@Test public void testStartAndStop() throws Exception {
  String domain="foo";
  MBeanServer server=ManagementFactory.getPlatformMBeanServer();
  ObjectName oname=new ObjectName(domain,"bar","baz");
  server.registerMBean(new Foo(),oname);
  TomcatMBeanManager mgr=new TomcatMBeanManager(domain);
  assertTrue(server.isRegistered(oname));
  mgr.start();
  assertFalse(server.isRegistered(oname));
  server.registerMBean(new Foo(),oname);
  assertTrue(server.isRegistered(oname));
  mgr.stop();
  assertFalse(server.isRegistered(oname));
}
 

Example 19

From project jbosgi, under directory /testsuite/example/src/test/java/org/jboss/test/osgi/example/jmx/bundle/.

Source file: MBeanActivator.java

  18 
vote

public void stop(BundleContext context){
  ServiceReference sref=context.getServiceReference(MBeanServer.class.getName());
  if (sref != null) {
    MBeanServer mbeanServer=(MBeanServer)context.getService(sref);
    unregisterMBean(mbeanServer);
  }
}
 

Example 20

From project jbosgi-jmx, under directory /bundle/src/main/java/org/jboss/osgi/jmx/internal/.

Source file: MBeanServerService.java

  18 
vote

public MBeanServer registerMBeanServer(){
  ServiceReference sref=context.getServiceReference(MBeanServer.class.getName());
  if (sref != null) {
    MBeanServer mbeanServer=(MBeanServer)context.getService(sref);
    LOGGER.debugf("Found MBeanServer fom service: %s",mbeanServer.getDefaultDomain());
    return mbeanServer;
  }
  MBeanServer mbeanServer=getMBeanServer();
  context.registerService(MBeanServer.class.getName(),mbeanServer,null);
  LOGGER.debugf("MBeanServer registered");
  return mbeanServer;
}
 

Example 21

From project jboss-ejb3-tutorial, under directory /service/src/org/jboss/tutorial/service/bean/.

Source file: ServiceThree.java

  18 
vote

public String serviceOneHello() throws Exception {
  Object[] args=new Object[0];
  String[] signature=new String[0];
  System.out.println("ServiceThree - Calling ServiceOne.sayHello() via JMX server");
  MBeanServer server=(MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
  return (String)server.invoke(serviceOneName,"sayHello",args,signature);
}
 

Example 22

From project jmx-cli, under directory /src/test/java/org/clamshellcli/jmx/.

Source file: JmxAgent.java

  18 
vote

public void start() throws Exception {
  System.out.println("Starting JmxAgent on RMI port " + port);
  System.setProperty("java.rmi.server.randomIDs","true");
  reg=LocateRegistry.createRegistry(port);
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  HashMap<String,Object> env=new HashMap<String,Object>();
  JMXServiceURL url=new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi");
  server=JMXConnectorServerFactory.newJMXConnectorServer(url,env,mbs);
  System.out.println("Agent RMI connector exported with url " + url.toString());
  server.start();
}
 

Example 23

From project jmxmonitor, under directory /jmxmonitor/src/test/java/uk/co/gidley/jmxmonitor/monitoring/.

Source file: MultiNamedMBeanTest.java

  18 
vote

@Override public void registerTestMBeans() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException {
  MBeanServer mBeanServer=ManagementFactory.getPlatformMBeanServer();
  ObjectName bean1=new ObjectName("uk.co.gidley.jmxmonitor:type=Bean1[guff]");
  ObjectName bean2=new ObjectName("uk.co.gidley.jmxmonitor:type=Bean1[guff2]");
  ping1=mBeanServer.registerMBean(new Ping("1"),bean1);
  ping2=mBeanServer.registerMBean(new Ping("2"),bean2);
}
 

Example 24

From project jolokia, under directory /agent/core/src/main/java/org/jolokia/detector/.

Source file: WeblogicDetector.java

  18 
vote

/** 
 * Adde Weblogic specific runtime MBeanServer
 * @param servers set to add own MBean servers
 */
@Override public void addMBeanServers(Set<MBeanServer> servers){
  InitialContext ctx;
  try {
    ctx=new InitialContext();
    MBeanServer server=(MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");
    if (server != null) {
      servers.add(server);
    }
  }
 catch (  NamingException e) {
  }
}
 

Example 25

From project karaf, under directory /http/core/src/test/java/org/apache/karaf/http/core/internal/.

Source file: HttpTest.java

  18 
vote

@Test public void testRegisterMBean() throws Exception {
  Http httpMBean=new Http(new ServletServiceImpl(new ServletEventHandler()));
  MBeanServer mbeanServer=ManagementFactory.getPlatformMBeanServer();
  mbeanServer.registerMBean(httpMBean,new ObjectName("org.apache.karaf:type=http,name=root"));
  TabularData data=httpMBean.getServlets();
}
 

Example 26

From project kernel_1, under directory /exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/impl/jboss/.

Source file: JBossTransactionService.java

  18 
vote

/** 
 * {@inheritDoc}
 */
@Override public int getDefaultTimeout(){
  try {
    MBeanServer server=(MBeanServer)MBeanServerFactory.findMBeanServer(null).iterator().next();
    return (Integer)server.getAttribute(ObjectName.getInstance("jboss:service=TransactionManager"),"TransactionTimeout");
  }
 catch (  Exception e) {
    throw new IllegalStateException(e);
  }
}
 

Example 27

From project logback, under directory /logback-access/src/main/java/ch/qos/logback/access/filter/.

Source file: CountingFilter.java

  18 
vote

@Override public void stop(){
  super.stop();
  try {
    MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
    ObjectName on=new ObjectName("totp:Filter=1");
    mbs.unregisterMBean(on);
  }
 catch (  Exception e) {
    addError("Failed to unregister mbean",e);
  }
}
 

Example 28

From project mcore, under directory /src/com/massivecraft/mcore4/xlib/mongodb/.

Source file: DBPortPool.java

  18 
vote

Holder(MongoOptions options){
  _options=options;
{
    MBeanServer temp=null;
    try {
      temp=ManagementFactory.getPlatformMBeanServer();
    }
 catch (    Throwable t) {
    }
    _server=temp;
  }
}
 

Example 29

From project Metamorphosis, under directory /metamorphosis-server/src/main/java/com/taobao/metamorphosis/server/utils/.

Source file: MetaMBeanServer.java

  18 
vote

public static void registMBean(Object o,String name){
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  if (null != mbs) {
    try {
      mbs.registerMBean(o,new ObjectName(o.getClass().getPackage().getName() + ":type=" + o.getClass().getSimpleName()+ (null == name ? ",id=" + o.hashCode() : ",name=" + name + "-"+ o.hashCode())));
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
}
 

Example 30

From project ODE-X, under directory /cli/src/test/java/org/apache/ode/cli/.

Source file: CLITest.java

  18 
vote

@AfterClass public static void tearDownAfterClass() throws Exception {
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  mbs.unregisterMBean(ObjectName.getInstance(Repository.OBJECTNAME));
  cntorServer.stop();
  log.info("JMXServer stopped");
}
 

Example 31

From project orientdb, under directory /server/src/main/java/com/orientechnologies/orient/server/.

Source file: OServer.java

  18 
vote

public OServer() throws ClassNotFoundException, MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
  threadGroup=new ThreadGroup("OrientDB Server");
  OCommandManager.instance().register(OCommandScript.class,OCommandExecutorScript.class);
  OGlobalConfiguration.STORAGE_KEEP_OPEN.setValue(true);
  System.setProperty("com.sun.management.jmxremote","true");
  MBeanServer mBeanServer=ManagementFactory.getPlatformMBeanServer();
  mBeanServer.registerMBean(OProfiler.getInstance().startRecording(),new ObjectName("OrientDB:type=Profiler"));
  managedServer=new OrientServer();
  mBeanServer.registerMBean(managedServer,new ObjectName("OrientDB:type=Server"));
  shutdownHook=new OServerShutdownHook();
}
 

Example 32

From project perf4j, under directory /src/main/java/org/perf4j/log4j/.

Source file: JmxAttributeStatisticsAppender.java

  18 
vote

@Override public void close(){
  try {
    MBeanServer mBeanServer=getMBeanServer();
    mBeanServer.unregisterMBean(new ObjectName(mBeanName));
  }
 catch (  Exception e) {
  }
}
 

Example 33

From project archaius, under directory /archaius-core/src/main/java/com/netflix/config/jmx/.

Source file: ConfigJMXManager.java

  17 
vote

public static ConfigMBean registerConfigMbean(AbstractConfiguration config){
  StandardMBean mbean=null;
  ConfigMBean bean=null;
  try {
    MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
    bean=new BaseConfigMBean(config);
    mbean=new StandardMBean(bean,ConfigMBean.class);
    mbs.registerMBean(mbean,getJMXObjectName(config,bean));
  }
 catch (  NotCompliantMBeanException e) {
    throw new RuntimeException("NotCompliantMBeanException",e);
  }
catch (  InstanceAlreadyExistsException e) {
    throw new RuntimeException("InstanceAlreadyExistsException",e);
  }
catch (  MBeanRegistrationException e) {
    throw new RuntimeException("MBeanRegistrationException",e);
  }
catch (  Exception e) {
    throw new RuntimeException("registerConfigMbeanException",e);
  }
  return bean;
}
 

Example 34

From project arquillian-core, under directory /protocols/jmx/src/main/java/org/jboss/arquillian/protocol/jmx/.

Source file: JMXCommandService.java

  17 
vote

@SuppressWarnings("unchecked") @Override public <T>T execute(Command<T> command){
  MBeanServer server=JMXTestRunner.localMBeanServer;
  try {
    ObjectName runner=new ObjectName(JMXTestRunner.OBJECT_NAME);
    server.invoke(runner,"send",new Object[]{command},new String[]{Command.class.getName()});
    long timeoutTime=System.currentTimeMillis() + TIMEOUT;
    while (timeoutTime > System.currentTimeMillis()) {
      Command<?> newCommand=(Command<?>)server.invoke(runner,"receive",new Object[]{},new String[]{});
      if (newCommand != null) {
        if (newCommand.getThrowable() != null) {
          throw new RuntimeException(newCommand.getThrowable());
        }
        if (newCommand.getResult() != null) {
          return (T)newCommand.getResult();
        }
      }
      try {
        Thread.sleep(100);
      }
 catch (      Exception e) {
        throw new RuntimeException(e);
      }
    }
    throw new RuntimeException("No command response within timeout of " + TIMEOUT + " ms.");
  }
 catch (  Exception e) {
    throw new RuntimeException("Could not communicate with client side",e);
  }
}
 

Example 35

From project coala, under directory /assemblies/coala/src/main/java/org/openehealth/coala/lifecycle/.

Source file: FacesAppListener.java

  17 
vote

@Override public void processEvent(SystemEvent event) throws AbortProcessingException {
  if (event instanceof PostConstructApplicationEvent) {
    LOG.info("PostConstructApplicationEvent is called");
  }
  if (event instanceof PreDestroyApplicationEvent) {
    LOG.info("PreDestroyApplicationEvent is called");
    MBeanServer mbserver=null;
    ArrayList<MBeanServer> mbservers=MBeanServerFactory.findMBeanServer(null);
    if (mbservers.size() > 0) {
      mbserver=(MBeanServer)mbservers.get(0);
    }
    if (mbserver != null) {
      LOG.info("Found our MBean server instance...");
    }
 else {
      mbserver=MBeanServerFactory.createMBeanServer();
    }
    try {
      Set<ObjectInstance> mbeans=mbserver.queryMBeans(null,null);
      for (      ObjectInstance mb : mbeans) {
        if (mb.getObjectName().getCanonicalName().contains("camelContext-pdq")) {
          LOG.info("Successfully removed MBean: " + mb.getObjectName().getCanonicalName());
          mbserver.unregisterMBean(mb.getObjectName());
        }
 else         if (mb.getObjectName().getCanonicalName().contains("camelContext-xds")) {
          LOG.info("Successfully removed MBean: " + mb.getObjectName().getCanonicalName());
          mbserver.unregisterMBean(mb.getObjectName());
        }
      }
    }
 catch (    InstanceNotFoundException infe) {
      LOG.warn("Ignoring to unregister pdq/xds camelContext, as it was not found!?");
    }
catch (    Throwable e) {
      LOG.error(e.getLocalizedMessage(),e);
    }
  }
}
 

Example 36

From project dawn-isenciaui, under directory /com.isencia.passerelle.workbench.model/src/main/java/com/isencia/passerelle/workbench/model/jmx/.

Source file: RemoteManagerAgent.java

  17 
vote

/** 
 * Call this method to start the agent which will deploy the service on JMX.
 * @throws Exception 
 */
public void start() throws Exception {
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  try {
    try {
      stop(false);
    }
 catch (    Exception ignored) {
    }
    mbs.registerMBean(remoteManager,REMOTE_MANAGER);
    JMXConnectorServer cs=JMXConnectorServerFactory.newJMXConnectorServer(serverUrl,null,mbs);
    cs.start();
    logger.debug("Workflow service started on " + serverUrl);
  }
 catch (  Exception e) {
    logger.error("Cannot connect manager agent to provide rmi access to ptolomy manager",e);
    com.isencia.passerelle.workbench.model.activator.Activator.getDefault().getLog().log(new Status(Status.ERROR,Activator.PLUGIN_ID,"The connection of the workflow service has failed to " + serverUrl + ". No workflows can be run!",e));
    throw e;
  }
}
 

Example 37

From project des, under directory /daemon/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/jmx/.

Source file: Agent.java

  17 
vote

/** 
 * Starts instance of HtmlAdapterServer.
 * @deprecated
 */
public void start(){
  MBeanServer server=MBeanServerFactory.createMBeanServer();
  Object html=createServer();
  try {
    log.info("Registering HtmlAdaptorServer instance.");
    server.registerMBean(html,new ObjectName("Adaptor:name=html,port=8082"));
    log.info("Registering HierarchyDynamicMBean instance.");
    HierarchyDynamicMBean hdm=new HierarchyDynamicMBean();
    server.registerMBean(hdm,new ObjectName("log4j:hiearchy=default"));
  }
 catch (  JMException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
catch (  RuntimeException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
  startServer(html);
}
 

Example 38

From project EasySOA, under directory /easysoa-registry/easysoa-registry-api/easysoa-remote-frascati/src/main/java/org/easysoa/sca/frascati/.

Source file: RemoteFraSCAtiServiceProvider.java

  17 
vote

/** 
 * @throws Exception 
 */
public void stopFraSCAtiService() throws Exception {
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  ObjectName name;
  try {
    name=new ObjectName("SCA domain:name0=*,*");
    Set<ObjectName> names=mbs.queryNames(name,name);
    for (    ObjectName objectName : names) {
      mbs.unregisterMBean(objectName);
    }
    mbs.unregisterMBean(new ObjectName("org.ow2.frascati.jmx:name=FrascatiJmx"));
  }
 catch (  MalformedObjectNameException e) {
  }
catch (  NullPointerException e) {
  }
catch (  MBeanRegistrationException e) {
  }
catch (  InstanceNotFoundException e) {
  }
  Object lifeCycleController=componentClass.getDeclaredMethod("getFcInterface",new Class<?>[]{String.class}).invoke(factory,new Object[]{"lifecycle-controller"});
  lifecycleClass.getDeclaredMethod("stopFc").invoke(lifeCycleController);
  frascatiService=null;
  frascati=null;
  icl=null;
  Runtime.getRuntime().runFinalization();
  System.gc();
}
 

Example 39

From project fastjson, under directory /src/test/java/com/alibaba/json/test/benchmark/.

Source file: BenchmarkExecutor.java

  17 
vote

public long getYoungGC(){
  try {
    MBeanServer mbeanServer=ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName;
    if (mbeanServer.isRegistered(new ObjectName("java.lang:type=GarbageCollector,name=ParNew"))) {
      objectName=new ObjectName("java.lang:type=GarbageCollector,name=ParNew");
    }
 else     if (mbeanServer.isRegistered(new ObjectName("java.lang:type=GarbageCollector,name=Copy"))) {
      objectName=new ObjectName("java.lang:type=GarbageCollector,name=Copy");
    }
 else {
      objectName=new ObjectName("java.lang:type=GarbageCollector,name=PS Scavenge");
    }
    return (Long)mbeanServer.getAttribute(objectName,"CollectionCount");
  }
 catch (  Exception e) {
    throw new RuntimeException("error");
  }
}
 

Example 40

From project galaxy, under directory /src/co/paralleluniverse/common/monitoring/.

Source file: Monitor.java

  17 
vote

public void registerMBean(){
  try {
    LOG.info("Registering MBean {}",name);
    MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
    ObjectName mxbeanName=new ObjectName(name);
    mbs.registerMBean(this,mxbeanName);
    this.registered=true;
  }
 catch (  InstanceAlreadyExistsException ex) {
    throw new RuntimeException(ex);
  }
catch (  MBeanRegistrationException ex) {
    throw new RuntimeException(ex);
  }
catch (  NotCompliantMBeanException ex) {
    throw new AssertionError(ex);
  }
catch (  MalformedObjectNameException ex) {
    throw new AssertionError(ex);
  }
}
 

Example 41

From project gnip4j, under directory /core/src/main/java/com/zaubersoftware/gnip4j/api/support/jmx/sun/.

Source file: SunJMXProvider.java

  17 
vote

@Override public final void registerBean(final GnipStream stream,final StreamStats streamStats){
  final MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  try {
    ObjectName mbeanName=getStreamName(stream);
    mbs.registerMBean(new com.zaubersoftware.gnip4j.api.support.jmx.sun.StreamStats(streamStats),mbeanName);
  }
 catch (  InstanceAlreadyExistsException e) {
    throw new IllegalArgumentException(e);
  }
catch (  MBeanRegistrationException e) {
    throw new IllegalArgumentException(e);
  }
catch (  NotCompliantMBeanException e) {
    throw new IllegalArgumentException(e);
  }
}
 

Example 42

From project ihbase, under directory /src/main/java/org/apache/hadoop/hbase/.

Source file: JmxHelper.java

  17 
vote

/** 
 * Registers an MBean with the platform MBean server. if an MBean with the same name exists it will be unregistered and the provided MBean would replace it
 * @param objectName the object name
 * @param mbean      the mbean class
 */
public static void registerMBean(ObjectName objectName,Object mbean){
  final MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  if (mbs.isRegistered(objectName)) {
    try {
      LOG.info("unregister: " + objectName);
      mbs.unregisterMBean(objectName);
    }
 catch (    InstanceNotFoundException e) {
      throw new IllegalStateException("mbean " + objectName + " failed unregistration",e);
    }
catch (    MBeanRegistrationException e) {
      throw new IllegalStateException("mbean " + objectName + " failed unregistration",e);
    }
  }
  try {
    LOG.info("register: " + objectName);
    mbs.registerMBean(mbean,objectName);
  }
 catch (  InstanceAlreadyExistsException e) {
    throw new IllegalStateException("mbean " + objectName + " failed registration",e);
  }
catch (  MBeanRegistrationException e) {
    throw new IllegalStateException("mbean " + objectName + " failed registration",e);
  }
catch (  NotCompliantMBeanException e) {
    throw new IllegalStateException("mbean " + objectName + " failed registration",e);
  }
}
 

Example 43

From project iPage, under directory /src/test/java/com/github/zhongl/api/.

Source file: IPageTest.java

  17 
vote

@Test public void mbeanRegistration() throws Exception {
  dir=testDir("mbeanRegistration");
  MBeanServer server=ManagementFactory.getPlatformMBeanServer();
  iPage=stringIPage(dir,1,1,Long.MAX_VALUE);
  String domain="com.github.zhongl.ipage";
  String name=iPage.toString();
  ObjectName ephemerons=new ObjectNameBuilder(domain).withType("Ephemerons").withName(name).build();
  ObjectName storage=new ObjectNameBuilder(domain).withType("Storage").withName(name).build();
  ObjectName defragPolicy=new ObjectNameBuilder(domain).withType("DefragPolicy").withName(name).build();
  server.getMBeanInfo(ephemerons);
  server.getMBeanInfo(defragPolicy);
  iPage.stop();
  try {
    server.getMBeanInfo(ephemerons);
    fail("MBean should be unregistered.");
  }
 catch (  InstanceNotFoundException e) {
  }
  try {
    server.getMBeanInfo(storage);
    fail("MBean should be unregistered.");
  }
 catch (  InstanceNotFoundException e) {
  }
  try {
    server.getMBeanInfo(defragPolicy);
    fail("MBean should be unregistered.");
  }
 catch (  InstanceNotFoundException e) {
  }
}
 

Example 44

From project IronCount, under directory /src/main/java/com/jointhegrid/ironcount/manager/.

Source file: WorkerThread.java

  17 
vote

public WorkerThread(WorkloadManager m,Workload w){
  messagesProcessesed=new AtomicLong(0);
  processingTime=new AtomicLong(0);
  status=WorkerThreadStatus.NEW;
  wtId=UUID.randomUUID();
  workload=w;
  goOn=true;
  this.m=m;
  executor=Executors.newFixedThreadPool(1);
  try {
    zk=new ZooKeeper(m.getProps().getProperty(WorkloadManager.ZK_SERVER_LIST),3000,this);
  }
 catch (  IOException ex) {
    logger.error(ex);
    throw new RuntimeException(ex);
  }
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  try {
    mbs.registerMBean(this,new ObjectName(MBEAN_OBJECT_NAME + ",uuid=" + wtId));
  }
 catch (  Exception ex) {
    throw new RuntimeException(ex);
  }
}
 

Example 45

From project jboss-remoting, under directory /src/main/java/org/jboss/remoting3/remote/.

Source file: RemoteConnectionProvider.java

  17 
vote

RemoteConnectionProvider(final OptionMap optionMap,final ConnectionProviderContext connectionProviderContext) throws IOException {
  super(connectionProviderContext.getExecutor());
  xnio=connectionProviderContext.getXnio();
  sslEnabled=optionMap.get(Options.SSL_ENABLED,true);
  xnioWorker=connectionProviderContext.getXnioWorker();
  this.connectionProviderContext=connectionProviderContext;
  final int messageBufferSize=optionMap.get(RemotingOptions.RECEIVE_BUFFER_SIZE,8192);
  messageBufferPool=false ? new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR,messageBufferSize,optionMap.get(RemotingOptions.BUFFER_REGION_SIZE,messageBufferSize * 2)) : Buffers.allocatedBufferPool(BufferAllocator.BYTE_BUFFER_ALLOCATOR,messageBufferSize);
  final int framingBufferSize=messageBufferSize + 4;
  framingBufferPool=false ? new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR,framingBufferSize,optionMap.get(RemotingOptions.BUFFER_REGION_SIZE,framingBufferSize * 2)) : Buffers.allocatedBufferPool(BufferAllocator.BYTE_BUFFER_ALLOCATOR,framingBufferSize);
  try {
    final MBeanServer server=ManagementFactory.getPlatformMBeanServer();
    server.registerMBean(new RemoteConnectionProviderMXBean(){
      public void dumpConnectionState(){
        doDumpConnectionState();
      }
      public String dumpConnectionStateToString(){
        return doGetConnectionState();
      }
    }
,new ObjectName("jboss.remoting.handler","name",connectionProviderContext.getEndpoint().getName() + "-" + hashCode()));
  }
 catch (  Exception e) {
  }
}
 

Example 46

From project jmxutils, under directory /src/test/java/org/weakref/jmx/guice/.

Source file: TestMBeanModule.java

  17 
vote

@Test public void testExportedInDevelopmentStageToo() throws IntrospectionException, InstanceNotFoundException, ReflectionException {
  final ObjectName name=Util.getUniqueObjectName();
  Injector injector=Guice.createInjector(new MBeanModule(),new AbstractModule(){
    @Override protected void configure(){
      binder().requireExplicitBindings();
      binder().disableCircularProxies();
      bind(SimpleObject.class).asEagerSingleton();
      bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer());
      ExportBinder.newExporter(binder()).export(SimpleObject.class).as(name.getCanonicalName());
    }
  }
);
  MBeanServer server=injector.getInstance(MBeanServer.class);
  Assert.assertNotNull(server.getMBeanInfo(name));
}
 

Example 47

From project jsr107tck, under directory /cache-tests/src/test/java/org/jsr107/tck/statistics/.

Source file: JMXTest.java

  17 
vote

public static void main(String[] args) throws Exception {
  System.out.println("Starting -----------------");
  CacheManager cacheManager=Caching.getCacheManager("Yannis");
  MBeanServerRegistrationUtility mBeanServerRegistrationUtility=null;
  try {
    MBeanServer mBeanServer=ManagementFactory.getPlatformMBeanServer();
    cacheManager.createCacheBuilder("cache1").setStatisticsEnabled(true).build();
    cacheManager.createCacheBuilder("cache2").setStatisticsEnabled(true).build();
    mBeanServerRegistrationUtility=new MBeanServerRegistrationUtility(cacheManager,mBeanServer);
    ObjectName search=new ObjectName("javax.cache:*");
    System.out.println("size=" + mBeanServer.queryNames(search,null).size());
    Thread.sleep(60 * 1000);
    System.out.println("Done -----------------");
  }
  finally {
    if (mBeanServerRegistrationUtility != null)     mBeanServerRegistrationUtility.dispose();
    cacheManager.shutdown();
  }
}
 

Example 48

From project log4j, under directory /src/main/java/org/apache/log4j/jmx/.

Source file: Agent.java

  17 
vote

/** 
 * Starts instance of HtmlAdapterServer.
 * @deprecated
 */
public void start(){
  MBeanServer server=MBeanServerFactory.createMBeanServer();
  Object html=createServer();
  try {
    log.info("Registering HtmlAdaptorServer instance.");
    server.registerMBean(html,new ObjectName("Adaptor:name=html,port=8082"));
    log.info("Registering HierarchyDynamicMBean instance.");
    HierarchyDynamicMBean hdm=new HierarchyDynamicMBean();
    server.registerMBean(hdm,new ObjectName("log4j:hiearchy=default"));
  }
 catch (  JMException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
catch (  RuntimeException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
  startServer(html);
}
 

Example 49

From project log4jna, under directory /thirdparty/log4j/src/main/java/org/apache/log4j/jmx/.

Source file: Agent.java

  17 
vote

/** 
 * Starts instance of HtmlAdapterServer.
 * @deprecated
 */
public void start(){
  MBeanServer server=MBeanServerFactory.createMBeanServer();
  Object html=createServer();
  try {
    log.info("Registering HtmlAdaptorServer instance.");
    server.registerMBean(html,new ObjectName("Adaptor:name=html,port=8082"));
    log.info("Registering HierarchyDynamicMBean instance.");
    HierarchyDynamicMBean hdm=new HierarchyDynamicMBean();
    server.registerMBean(hdm,new ObjectName("log4j:hiearchy=default"));
  }
 catch (  JMException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
catch (  RuntimeException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
  startServer(html);
}
 

Example 50

From project monitor-event-tap, under directory /src/test/java/com/proofpoint/event/monitor/.

Source file: TestServer.java

  17 
vote

@BeforeMethod public void setup() throws Exception {
  ImmutableMap<String,String> config=ImmutableMap.of("monitor.file","src/test/resources/monitor.json");
  final MBeanServer mockMBeanServer=mock(MBeanServer.class);
  Injector injector=Guice.createInjector(new TestingNodeModule(),new TestingHttpServerModule(),new JsonModule(),new JaxrsModule(),new JmxHttpModule(),Modules.override(new JmxModule()).with(new Module(){
    @Override public void configure(    Binder binder){
      binder.bind(MBeanServer.class).toInstance(mockMBeanServer);
    }
  }
),new DiscoveryModule(),new MainModule(),new Module(){
    @Override public void configure(    Binder binder){
      binder.bind(Alerter.class).to(InMemoryAlerter.class).in(Scopes.SINGLETON);
    }
  }
,new ConfigurationModule(new ConfigurationFactory(config)));
  server=injector.getInstance(TestingHttpServer.class);
  Map<String,Monitor> monitors=newHashMap();
  for (  Monitor monitor : newArrayList(injector.getInstance(Key.get(new TypeLiteral<Set<Monitor>>(){
  }
)))) {
    monitors.put(monitor.getName(),monitor);
  }
  Assert.assertEquals(monitors.size(),6);
  scorerHttpMonitor=monitors.get("ScorerHttpMonitor");
  Assert.assertNotNull(scorerHttpMonitor);
  prsMessageMonitor=monitors.get("PrsMessageMonitor");
  Assert.assertNotNull(prsMessageMonitor);
  server.start();
  client=new AsyncHttpClient(new ApacheHttpClient(new HttpClientConfig()),Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build()));
}
 

Example 51

From project niravCS2103, under directory /CS2103/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/jmx/.

Source file: Agent.java

  17 
vote

/** 
 * Starts instance of HtmlAdapterServer.
 * @deprecated
 */
public void start(){
  MBeanServer server=MBeanServerFactory.createMBeanServer();
  Object html=createServer();
  try {
    log.info("Registering HtmlAdaptorServer instance.");
    server.registerMBean(html,new ObjectName("Adaptor:name=html,port=8082"));
    log.info("Registering HierarchyDynamicMBean instance.");
    HierarchyDynamicMBean hdm=new HierarchyDynamicMBean();
    server.registerMBean(hdm,new ObjectName("log4j:hiearchy=default"));
  }
 catch (  JMException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
catch (  RuntimeException e) {
    log.error("Problem while registering MBeans instances.",e);
    return;
  }
  startServer(html);
}
 

Example 52

From project obpro_team_p, under directory /twitter/twitter4j-core/src/test/java/twitter4j/.

Source file: MBeanServerRunner.java

  17 
vote

public static void main(String[] args) throws Exception {
  MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  ObjectName name=new ObjectName("twitter4j.mbean:type=APIStatistics");
  ObjectName name2=new ObjectName("twitter4j.mbean:type=APIStatisticsOpenMBean");
  APIStatistics statsMBean=new APIStatistics(100);
  mbs.registerMBean(statsMBean,name);
  APIStatisticsOpenMBean openMBean=new APIStatisticsOpenMBean(statsMBean);
  mbs.registerMBean(openMBean,name2);
  for (int i=0; i < 10; i++) {
    statsMBean.methodCalled("foo",5,true);
    statsMBean.methodCalled("bar",2,true);
    statsMBean.methodCalled("baz",10,true);
    statsMBean.methodCalled("foo",2,false);
  }
  Thread.sleep(1000 * 60 * 60);
}
 

Example 53

From project Arecibo, under directory /agent/src/main/java/com/ning/arecibo/agent/.

Source file: CoreMonitoringAgent.java

  15 
vote

/** 
 * @param args
 */
public static void main(String[] args){
  Injector injector=Guice.createInjector(Stage.PRODUCTION,new MBeanModule(),new AbstractModule(){
    @Override protected void configure(){
      bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer());
      bind(MBeanExporter.class).toInstance(MBeanExporter.withPlatformMBeanServer());
      bind(StatusPageHandler.class).asEagerSingleton();
    }
  }
,new LifecycleModule(),new DummyServiceLocatorModule(),new EventPublisherModule(EventSenderType.CLIENT),new EmbeddedJettyJerseyModule(),new RESTEventReceiverModule(EventProcessorImpl.class,"arecibo.agent:name=EventAPI"),new UDPEventReceiverModule(),new GalaxyModule(),new AgentModule());
  CoreMonitoringAgent coreMonitor=injector.getInstance(CoreMonitoringAgent.class);
  try {
    coreMonitor.run();
  }
 catch (  Exception e) {
    log.error(e,"Unable to start. Exiting.");
    System.exit(-1);
  }
}
 

Example 54

From project c3p0, under directory /src/java/com/mchange/v2/c3p0/management/.

Source file: DynamicPooledDataSourceManagerMBean.java

  15 
vote

public DynamicPooledDataSourceManagerMBean(PooledDataSource pds,String mbeanName,MBeanServer mbs) throws Exception {
  this.pds=pds;
  this.mbeanName=mbeanName;
  this.mbs=mbs;
  if (pds instanceof ComboPooledDataSource)   ;
 else   if (pds instanceof AbstractPoolBackedDataSource)   ((AbstractPoolBackedDataSource)pds).addPropertyChangeListener(pcl);
 else   logger.warning(this + "managing an unexpected PooledDataSource. Only top-level attributes will be available. PooledDataSource: " + pds);
  Exception e=reinitialize();
  if (e != null)   throw e;
}
 

Example 55

From project collector, under directory /src/test/java/com/ning/metrics/collector/endpoint/resources/.

Source file: JettyTestModule.java

  15 
vote

@Override protected void configure(){
  final ConfigurationObjectFactory configFactory=new CollectorConfigurationObjectFactory(System.getProperties());
  final CollectorConfig config=configFactory.build(AutoFlushConfig.class);
  bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer());
  install(new AbstractModule(){
    @Override protected void configure(){
      bind(ConfigurationObjectFactory.class).toInstance(configFactory);
      bind(CollectorConfig.class).toInstance(config);
    }
  }
);
  install(new RequestHandlersModule());
  install(new EventCollectorModule());
  install(new RealTimeQueueModule());
  install(new FiltersModule(config));
  install(new ServletModule(){
    @Override protected void configureServlets(){
      final Map<String,String> params=new HashMap<String,String>();
      params.put(PackagesResourceConfig.PROPERTY_PACKAGES,"com.ning.metrics.collector.endpoint");
      serve("*").with(GuiceContainer.class,params);
    }
  }
);
  final MockEventWriter writer=new MockEventWriter();
  bind(MockEventWriter.class).toInstance(writer);
  bind(PersistentWriterFactory.class).toInstance(new MockPersistentWriterFactory(new ThresholdEventWriter(writer,0,1)));
}
 

Example 56

From project components-ness-integration-testing, under directory /src/main/java/com/nesscomputing/testing/tweaked/.

Source file: TweakedModules.java

  15 
vote

public static TweakedModule getJmxModule(){
  return new TweakedModule(){
    @Override public Module getTestCaseModule(    final Config config){
      return getServiceModule(config);
    }
    @Override public Module getServiceModule(    final Config config){
      return new Module(){
        @Override public void configure(        final Binder binder){
          binder.bind(MBeanServer.class).to(TestingMBeanServer.class).in(Scopes.SINGLETON);
        }
      }
;
    }
  }
;
}
 

Example 57

From project components-ness-jmx, under directory /src/main/java/com/nesscomputing/jmx/starter/.

Source file: JmxExporter.java

  15 
vote

@Inject public JmxExporter(final MBeanServer server,final IOExceptionProvider<JmxExporterConfig> configProvider,@Named(JmxStarterModule.JMX_STARTER_NAME) final Map<String,String> env) throws IOException {
  this.config=configProvider.get();
  try {
    final String hostName=config.getHostname().getHostAddress();
    url=new JMXServiceURL(String.format("service:jmx:rmi://%s:%d/jndi/rmi://%s:%d/jmxrmi",hostName,config.getRmiServerPort(),hostName,config.getRmiRegistryPort()));
  }
 catch (  MalformedURLException e) {
    throw new IllegalStateException(e);
  }
  connectorServer=JMXConnectorServerFactory.newJMXConnectorServer(url,env,server);
}
 

Example 58

From project guice-jit-providers, under directory /extensions/jmx/src/com/google/inject/tools/jmx/.

Source file: Manager.java

  15 
vote

/** 
 * Registers all the bindings of an Injector with the given MBean server. Consider using the name of your root  {@link Module} class as the domain.
 */
public static void manage(MBeanServer server,String domain,Injector injector){
  for (  Binding<?> binding : injector.getBindings().values()) {
    StringBuilder name=new StringBuilder();
    name.append(domain).append(":");
    Key<?> key=binding.getKey();
    name.append("type=").append(quote(key.getTypeLiteral().toString()));
    Annotation annotation=key.getAnnotation();
    if (annotation != null) {
      name.append(",annotation=").append(quote(annotation.toString()));
    }
 else {
      Class<? extends Annotation> annotationType=key.getAnnotationType();
      if (annotationType != null) {
        name.append(",annotation=").append(quote("@" + annotationType.getName()));
      }
    }
    try {
      server.registerMBean(new ManagedBinding(binding),new ObjectName(name.toString()));
    }
 catch (    MalformedObjectNameException e) {
      throw new RuntimeException("Bad object name: " + name.toString(),e);
    }
catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
}
 

Example 59

From project immutant, under directory /modules/core/src/main/java/org/immutant/core/as/.

Source file: CoreSubsystemAdd.java

  15 
vote

@SuppressWarnings("serial") protected void addImmutantService(final OperationContext context,ServiceVerificationHandler verificationHandler,List<ServiceController<?>> newControllers) throws IOException {
  Immutant immutant=new Immutant();
  newControllers.add(context.getServiceTarget().addService(CoreServices.IMMUTANT,immutant).setInitialMode(Mode.ACTIVE).addListener(verificationHandler).install());
  String mbeanName=ObjectNameFactory.create("Immutant",new Hashtable<String,String>(){
{
      put("type","version");
    }
  }
).toString();
  MBeanRegistrationService<ImmutantMBean> mbeanService=new MBeanRegistrationService<ImmutantMBean>(mbeanName);
  newControllers.add(context.getServiceTarget().addService(CoreServices.IMMUTANT.append("mbean"),mbeanService).addDependency(DependencyType.OPTIONAL,MBeanServerService.SERVICE_NAME,MBeanServer.class,mbeanService.getMBeanServerInjector()).addDependency(CoreServices.IMMUTANT,ImmutantMBean.class,mbeanService.getValueInjector()).addListener(verificationHandler).setInitialMode(Mode.PASSIVE).install());
}
 

Example 60

From project jbosgi-framework, under directory /itest/src/test/java/org/jboss/test/osgi/framework/classloader/.

Source file: SystemPackageDependencyTestCase.java

  15 
vote

private JavaArchive getBundleF(){
  final JavaArchive archive=ShrinkWrap.create(JavaArchive.class,"bundleF");
  archive.addClasses(SimpleManagementActivator.class);
  archive.setManifest(new Asset(){
    public InputStream openStream(){
      OSGiManifestBuilder builder=OSGiManifestBuilder.newInstance();
      builder.addBundleManifestVersion(2);
      builder.addBundleSymbolicName(archive.getName());
      builder.addBundleActivator(SimpleManagementActivator.class);
      builder.addImportPackages(BundleActivator.class,MBeanServer.class);
      return builder.openStream();
    }
  }
);
  return archive;
}
 

Example 61

From project jboss-modules, under directory /src/main/java/org/jboss/modules/.

Source file: ModuleLoader.java

  15 
vote

RealMBeanReg(){
  server=AccessController.doPrivileged(new PrivilegedAction<MBeanServer>(){
    public MBeanServer run(){
      return ManagementFactory.getPlatformMBeanServer();
    }
  }
);
}
 

Example 62

From project jboss-polyglot, under directory /core-extensions/src/main/java/org/projectodd/polyglot/core_extensions/.

Source file: AtRuntimeInstaller.java

  15 
vote

public ServiceName installMBean(final ServiceName name,final MBeanRegistrationService<?> mbeanService){
  final ServiceName mbeanName=name.append("mbean");
  replaceService(mbeanName,new Runnable(){
    public void run(){
      getTarget().addService(mbeanName,mbeanService).addDependency(DependencyType.OPTIONAL,MBeanServerService.SERVICE_NAME,MBeanServer.class,mbeanService.getMBeanServerInjector()).setInitialMode(Mode.PASSIVE).install();
    }
  }
);
  return mbeanName;
}
 

Example 63

From project jdg, under directory /infinispan/src/main/java/org/jboss/as/clustering/infinispan/subsystem/.

Source file: CacheContainerAdd.java

  15 
vote

ServiceController<?> installContainerConfigurationService(ServiceTarget target,String containerName,String defaultCache,ModuleIdentifier moduleId,Transport transportConfig,String transportExecutor,String listenerExecutor,String evictionExecutor,String replicationQueueExecutor,ServiceVerificationHandler verificationHandler){
  ServiceName configServiceName=EmbeddedCacheManagerConfigurationService.getServiceName(containerName);
  EmbeddedCacheManagerDependencies dependencies=new EmbeddedCacheManagerDependencies(transportConfig);
  ServiceBuilder<EmbeddedCacheManagerConfiguration> configBuilder=target.addService(configServiceName,new EmbeddedCacheManagerConfigurationService(containerName,defaultCache,moduleId,dependencies)).addDependency(Services.JBOSS_SERVICE_MODULE_LOADER,ModuleLoader.class,dependencies.getModuleLoaderInjector()).addDependency(MBeanServerService.SERVICE_NAME,MBeanServer.class,dependencies.getMBeanServerInjector()).setInitialMode(ServiceController.Mode.ON_DEMAND);
  if (transportConfig != null) {
    if (transportExecutor != null) {
      addExecutorDependency(configBuilder,transportExecutor,transportConfig.getExecutorInjector());
    }
    ServiceName channelServiceName=ChannelService.getServiceName(containerName);
    configBuilder.addDependency(channelServiceName,Channel.class,transportConfig.getChannelInjector());
  }
  addExecutorDependency(configBuilder,listenerExecutor,dependencies.getListenerExecutorInjector());
  addScheduledExecutorDependency(configBuilder,evictionExecutor,dependencies.getEvictionExecutorInjector());
  addScheduledExecutorDependency(configBuilder,replicationQueueExecutor,dependencies.getReplicationQueueExecutorInjector());
  return configBuilder.install();
}
 

Example 64

From project jetty-project, under directory /jetty-jboss/src/main/java/org/jboss/jetty/.

Source file: JettyService.java

  15 
vote

/** 
 * Listen for our registration as an mbean and remember our name.
 * @see org.jboss.system.ServiceMBeanSupport#preRegister(javax.management.MBeanServer,javax.management.ObjectName)
 */
public ObjectName preRegister(MBeanServer server,ObjectName name) throws Exception {
  super.preRegister(server,name);
  name=getObjectName(server,name);
  _server=server;
  return name;
}
 

Example 65

From project maven-t7-plugin, under directory /src/main/java/com/googlecode/t7mp/.

Source file: StopMojo.java

  15 
vote

private void cleanupMBeanServer() throws MalformedObjectNameException, MBeanRegistrationException, InstanceNotFoundException {
  ArrayList<MBeanServer> servers=MBeanServerFactory.findMBeanServer(null);
  for (  MBeanServer server : servers) {
    ObjectName naming=new ObjectName("Catalina:*");
    for (    ObjectInstance object : server.queryMBeans(naming,null)) {
      server.unregisterMBean(object.getObjectName());
    }
  }
}
 

Example 66

From project meteo, under directory /core/src/main/java/com/ning/metrics/meteo/binder/.

Source file: RealtimeSystemModule.java

  15 
vote

/** 
 * Contributes bindings and other configurations for this module to  {@code binder}. <p/> <p><strong>Do not invoke this method directly</strong> to install submodules. Instead use {@link com.google.inject.Binder#install(com.google.inject.Module)}, which ensures that  {@link com.google.inject.Provides provider methods} arediscovered.
 */
@Override public void configure(final Binder binder){
  binder.bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer());
  binder.bind(JacksonJsonProvider.class).asEagerSingleton();
  final RealtimeSystemConfig config=new ConfigurationObjectFactory(System.getProperties()).build(RealtimeSystemConfig.class);
  binder.bind(RealtimeSystemConfig.class).toInstance(config);
  final Configuration configuration=new Configuration();
  if (!config.getEsperConfigurationFile().equals("")) {
    configuration.configure(new File(config.getEsperConfigurationFile()));
  }
  binder.bind(EPServiceProvider.class).toInstance(EPServiceProviderManager.getDefaultProvider(configuration));
  configureFromFile(binder,config.getConfigurationFile());
}