Java Code Examples for javax.management.ObjectName

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 arquillian-container-jbossas, under directory /jbossas-managed-4.2/src/main/java/org/jboss/arquillian/container/jbossas/managed_4_2/.

Source file: ManagementViewParser.java

  20 
vote

private static void scanDeployment(MBeanServerConnection connection,HTTPContext httpContext,String archiveName) throws Exception {
  ObjectName earExpression=new ObjectName("*:*,J2EEApplication=" + archiveName);
  Set<ObjectName> deployments=connection.queryNames(earExpression,null);
  for (  ObjectName deployment : deployments) {
    if (deployment.getKeyProperty("j2eeType").equals("WebModule")) {
      scanWar(connection,httpContext,deployment);
    }
  }
  ObjectName warExpression=new ObjectName("*:*,J2EEApplication=null,j2eeType=WebModule,name=" + archiveName);
  Set<ObjectName> warDeployments=connection.queryNames(warExpression,null);
  for (  ObjectName warDeployment : warDeployments) {
    scanWar(connection,httpContext,warDeployment);
  }
}
 

Example 2

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/management/.

Source file: DefaultMBeanRegistrar.java

  19 
vote

private void unregister(Hashtable<String,String> attributes){
  try {
    ObjectName name=this.createObjectName(attributes);
    if (this.server.isRegistered(name)) {
      this.server.unregisterMBean(name);
    }
  }
 catch (  Exception e) {
    logger.log(Level.WARN,e);
  }
}
 

Example 3

From project heritrix3, under directory /commons/src/main/java/org/archive/util/.

Source file: JndiUtils.java

  19 
vote

/** 
 * Testing code.
 * @param args Command line arguments.
 * @throws NullPointerException 
 * @throws MalformedObjectNameException 
 * @throws NamingException 
 * @throws InvalidNameException 
 */
public static void main(String[] args) throws MalformedObjectNameException, NullPointerException, InvalidNameException, NamingException {
  final ObjectName on=new ObjectName("org.archive.crawler:" + "type=Service,name=Heritrix00,host=debord.archive.org");
  Context c=getSubContext(getCompoundName(on.getDomain()));
  CompoundName key=bindObjectName(c,on);
  Reference r=(Reference)c.lookup(key);
  for (Enumeration<RefAddr> e=r.getAll(); e.hasMoreElements(); ) {
    System.out.println(e.nextElement());
  }
  unbindObjectName(c,on);
}
 

Example 4

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

Source file: JMXTestRunner.java

  18 
vote

public ObjectName registerMBean(MBeanServer mbeanServer) throws JMException {
  ObjectName oname=new ObjectName(JMXTestRunnerMBean.OBJECT_NAME);
  mbeanServer.registerMBean(this,oname);
  log.fine("JMXTestRunner registered: " + oname);
  localMBeanServer=mbeanServer;
  return oname;
}
 

Example 5

From project arquillian_deprecated, under directory /containers/jbossas-remote-5/src/main/java/org/jboss/arquillian/container/jbossas/remote_5_0/.

Source file: ManagementViewParser.java

  18 
vote

/** 
 * @param connection
 * @param httpContext
 * @param archiveName
 */
private static void scanDeployment(MBeanServerConnection connection,HTTPContext httpContext,String archiveName) throws Exception {
  ObjectName earExpression=new ObjectName("*:*,J2EEApplication=" + archiveName);
  Set<ObjectName> deployments=connection.queryNames(earExpression,null);
  for (  ObjectName deployment : deployments) {
    if (deployment.getKeyProperty("j2eeType").equals("WebModule")) {
      scanWar(connection,httpContext,deployment);
    }
  }
}
 

Example 6

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 7

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 8

From project camel-zookeeper, under directory /src/test/java/org/apache/camel/component/zookeeper/.

Source file: ZooKeeperEndpointTest.java

  18 
vote

public synchronized void testEnpointConfigurationCanBeSetViaJMX() throws Exception {
  Set s=mbsc.queryNames(new ObjectName(domainName + ":type=endpoints,*"),null);
  assertEquals("Could not find  endpoints: " + s,2,s.size());
  ObjectName zepName=new ArrayList<ObjectName>(s).get(0);
  verifyManagedAttribute(zepName,"Path","/someotherpath");
  verifyManagedAttribute(zepName,"Create",true);
  verifyManagedAttribute(zepName,"Repeat",true);
  verifyManagedAttribute(zepName,"ListChildren",true);
  verifyManagedAttribute(zepName,"AwaitExistence",true);
  verifyManagedAttribute(zepName,"Timeout",12345);
  verifyManagedAttribute(zepName,"Backoff",12345L);
  mbsc.invoke(zepName,"clearServers",null,JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("clearServers",null)));
  mbsc.invoke(zepName,"addServer",new Object[]{"someserver:12345"},JmxUtils.getMethodSignature(ZooKeeperEndpoint.class.getMethod("addServer",new Class[]{String.class})));
}
 

Example 9

From project chililog-server, under directory /src/main/java/org/chililog/server/engine/.

Source file: MqService.java

  18 
vote

/** 
 * Gets the queue control management class
 * @param queueAddress Address of queue
 * @param queueName Name of queue
 * @return <code>QueueControl</code> that can be used for managing queues. Null if returned if queue not found
 * @throws Exception
 */
public QueueControl getQueueControl(String queueAddress,String queueName) throws Exception {
  ObjectName objectName=ObjectNameBuilder.DEFAULT.getQueueObjectName(new SimpleString(queueAddress),new SimpleString(queueName));
  if (!_hornetqServer.getMBeanServer().isRegistered(objectName)) {
    return null;
  }
  return (QueueControl)MBeanServerInvocationHandler.newProxyInstance(_hornetqServer.getMBeanServer(),objectName,QueueControl.class,false);
}
 

Example 10

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

Source file: ApplicationManager.java

  18 
vote

@Override public void doProcess(HttpServletRequest request,MBeanServerConnection mbsc) throws Exception {
  String name=request.getParameter(Parameters.OBJECT_NAME);
  ObjectName objectName=new ObjectName(name);
  if (isContext(objectName,mbsc)) {
    mbsc.invoke(objectName,"start",null,null);
    String path=(String)mbsc.getAttribute(objectName,"contextPath");
    request.getSession().setAttribute(Attributes.INFO,"Application with context path " + path + " sucessfully started");
  }
 else   request.getSession().setAttribute(Attributes.WARN,"Could not found application");
}
 

Example 11

From project cloudhopper-smpp, under directory /src/main/java/com/cloudhopper/smpp/impl/.

Source file: DefaultSmppServer.java

  18 
vote

private void registerMBean(){
  if (configuration == null) {
    return;
  }
  if (configuration.isJmxEnabled()) {
    try {
      ObjectName name=new ObjectName(configuration.getJmxDomain() + ":name=" + configuration.getName());
      ManagementFactory.getPlatformMBeanServer().registerMBean(this,name);
    }
 catch (    Exception e) {
      logger.error("Unable to register DefaultSmppServerMXBean [{}]",configuration.getName(),e);
    }
  }
}
 

Example 12

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 13

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

Source file: JmxExporterTest.java

  18 
vote

@Test public void doTest() throws Exception {
  ObjectName beanName=new ObjectName("com.nesscomputing.config:n0=com,n1=nesscomputing,n2=config,n3=JmxExporterTest$MyBean");
  Assert.assertEquals("foo",server.getAttribute(beanName,"x"));
  Assert.assertEquals("3",server.getAttribute(beanName,"y"));
  Assert.assertEquals("10s",server.getAttribute(beanName,"z"));
}
 

Example 14

From project dawn-isencia, under directory /com.isencia.passerelle.engine/src/main/java/com/isencia/passerelle/statistics/.

Source file: StatisticsServiceImpl.java

  18 
vote

public void registerStatistics(NamedStatistics s){
  try {
    ObjectName objName=new ObjectName(getServerName() + ":name=" + s.getName());
    registerMBean(s,objName);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 15

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

Source file: BundleWebappLoader.java

  18 
vote

private void unregisterClassLoaderMBean(){
  try {
    StandardContext ctx=(StandardContext)getContainer();
    ObjectName classLoaderObjectName=createClassLoaderObjectName(ctx);
    Registry.getRegistry(null,null).unregisterComponent(classLoaderObjectName);
  }
 catch (  Throwable t) {
    log.error("LifecycleException ",t);
  }
}
 

Example 16

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

Source file: SunJMXProvider.java

  18 
vote

@Override public final void unregister(final GnipStream stream){
  final ObjectName name=getStreamName(stream);
  try {
    ManagementFactory.getPlatformMBeanServer().unregisterMBean(name);
  }
 catch (  MBeanRegistrationException e) {
    throw new RuntimeException(e);
  }
catch (  InstanceNotFoundException e) {
    logger.warn("Unknown stream: " + name);
  }
}
 

Example 17

From project hornetq-version-tests, under directory /src/test/java/org/hornetq/failover/.

Source file: SimpleFailoverIFT.java

  18 
vote

private void kill(String nodeName) throws Exception {
  ObjectName on=ObjectName.getInstance("org.hornetq." + nodeName + ":module=Core,type=Server");
  JMXConnector connector=JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL),new HashMap<String,String>());
  MBeanServerConnection mbsc=connector.getMBeanServerConnection();
  HornetQServerControl serverControl=MBeanServerInvocationHandler.newProxyInstance(mbsc,on,HornetQServerControl.class,false);
  try {
    serverControl.forceFailover();
  }
 catch (  Exception e) {
  }
}
 

Example 18

From project advanced, under directory /management/src/main/java/org/neo4j/management/impl/.

Source file: KernelProxy.java

  17 
vote

private static ObjectName createObjectName(String domain,Hashtable<String,String> properties,String beanName,boolean query,String... extraNaming){
  properties.put("name",beanName);
  for (int i=0; i < extraNaming.length; i++) {
    properties.put("name" + i,extraNaming[i]);
  }
  ObjectName result;
  try {
    result=new ObjectName(domain,properties);
    if (query)     result=ObjectName.getInstance(result.toString() + ",*");
  }
 catch (  MalformedObjectNameException e) {
    return null;
  }
  return result;
}
 

Example 19

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

Source file: MBeanResource.java

  17 
vote

@GET @Produces(MediaType.APPLICATION_JSON) public List<MBeanRepresentation> getMBeans() throws JMException {
  ImmutableList.Builder<MBeanRepresentation> mbeans=ImmutableList.builder();
  for (  ObjectName objectName : mbeanServer.queryNames(new ObjectName("*:*"),null)) {
    mbeans.add(new MBeanRepresentation(mbeanServer,objectName,objectMapper));
  }
  return mbeans.build();
}
 

Example 20

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

Source file: ConfigJMXManager.java

  17 
vote

private static ObjectName getJMXObjectName(AbstractConfiguration config,ConfigMBean bean) throws Exception {
  try {
    Class<? extends ConfigMBean> c=bean.getClass();
    String className=c.getName();
    int lastDot=className.lastIndexOf('.');
    ObjectName name=new ObjectName("Config-" + className.substring(0,lastDot) + ":class="+ className.substring(lastDot + 1));
    return name;
  }
 catch (  MalformedObjectNameException e) {
    throw new RuntimeException("MalformedObjectNameException",e);
  }
catch (  NullPointerException e) {
    throw new RuntimeException("NullPointerException",e);
  }
}
 

Example 21

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

Source file: JMXMonitoringProfilePoller.java

  17 
vote

private void init(){
  JMXClient client=null;
  try {
    client=new JMXClient(String.format("%s:%s",host,guiceDefaults.getJmxPort()));
    ObjectName objectName=new ObjectName(NING_JMX_NAME_MONITORING_PROFILE);
    if (client.getMBeanServerConnection().isRegistered(objectName)) {
      String[] list=(String[])client.getMBeanServerConnection().getAttribute(objectName,ATTR_MONITORING_PROFILE);
      for (      String line : list) {
        try {
          Config config=parseOldFormatLine(line);
          if (config != null) {
            configs.add(config);
          }
        }
 catch (        Exception e) {
          log.info(e,"Could not parse config line '" + line + "', for '"+ host+ ":"+ guiceDefaults.getJmxPort()+ "', for core monitoring file");
        }
      }
      log.info("Loaded " + configs.size() + " configs via registered monitoring profile for host '"+ host+ "'");
    }
 else {
      log.info("No registered monitoring profile found for host '" + host + "'");
    }
  }
 catch (  Exception e) {
    log.info("Could not poll '" + host + ":"+ guiceDefaults.getJmxPort()+ "' for core monitoring file",e);
  }
 finally {
    if (client != null) {
      try {
        client.close();
      }
 catch (      IOException e) {
        log.warn("Problem closing jmx client connection",e);
      }
    }
  }
}
 

Example 22

From project arquillian-container-tomcat, under directory /tomcat-common/src/main/java/org/jboss/arquillian/container/tomcat/.

Source file: ProtocolMetadataParser.java

  17 
vote

protected Set<ObjectInstance> getServletMBeans(JMXConnector jmxc,String context) throws IOException {
  MBeanServerConnection mbsc=jmxc.getMBeanServerConnection();
  String catalinaServlet=String.format(catalinaServletTemplate,configuration.getJmxVirtualHost(),context);
  ObjectName servletON;
  try {
    servletON=ObjectName.getInstance(catalinaServlet);
  }
 catch (  MalformedObjectNameException e) {
    throw new IllegalArgumentException("Unable to retrieve catalina MBeans for protocol metadata construction.\n" + "Following object name is not valid: " + catalinaServlet,e);
  }
catch (  NullPointerException e) {
    throw new IllegalArgumentException("Unable to retrieve catalina MBeans for protocol metadata construction.\n" + "Object name must not be null",e);
  }
  return mbsc.queryMBeans(servletON,null);
}
 

Example 23

From project arquillian-container-was, under directory /was-remote-7/src/main/java/org/jboss/arquillian/container/was/remote_7/.

Source file: DeploymentNotificationListener.java

  17 
vote

public DeploymentNotificationListener(AdminClient adminClient,NotificationFilterSupport support,Object handBack,String eventTypeToCheck) throws Exception {
  super();
  this.adminClient=adminClient;
  this.filterSupport=support;
  this.eventTypeToCheck=eventTypeToCheck;
  this.objectName=(ObjectName)adminClient.queryNames(new ObjectName("WebSphere:type=AppManagement,*"),null).iterator().next();
  adminClient.addNotificationListener(objectName,this,filterSupport,handBack);
}
 

Example 24

From project astyanax, under directory /src/main/java/com/netflix/astyanax/connectionpool/impl/.

Source file: ConnectionPoolMBeanManager.java

  17 
vote

public synchronized void registerMonitor(String name,ConnectionPool<?> pool){
  String monitorName=generateMonitorName(name);
  if (!monitors.containsKey(monitorName)) {
    JmxConnectionPoolMonitorMBean mbean;
    try {
      LOG.info("Registering mbean: " + monitorName);
      ObjectName oName=new ObjectName(monitorName);
      mbean=new JmxConnectionPoolMonitor(pool);
      monitors.put(monitorName,mbean);
      mbs.registerMBean(mbean,oName);
    }
 catch (    Exception e) {
      LOG.error(e.getMessage());
      monitors.remove(monitorName);
    }
  }
}
 

Example 25

From project blacktie, under directory /blacktie-admin-services/src/main/java/org/jboss/narayana/blacktie/administration/.

Source file: BlacktieStompAdministrationService.java

  17 
vote

private static boolean isDeployQueue(String serviceName) throws Exception {
  boolean conversational=false;
  String type="queue";
  if (!serviceName.startsWith(".")) {
    conversational=(Boolean)getProperty("blacktie." + serviceName + ".conversational");
    type=(String)getProperty("blacktie." + serviceName + ".type");
  }
  String prefix=null;
  if (conversational) {
    prefix="BTC_";
  }
 else {
    prefix="BTR_";
  }
  ObjectName objName=new ObjectName("jboss.as:subsystem=messaging,hornetq-server=default,jms-" + type + "="+ prefix+ "*");
  ObjectInstance[] dests=getMBeanServerConnection().queryMBeans(objName,null).toArray(new ObjectInstance[]{});
  for (int i=0; i < dests.length; i++) {
    String serviceComponentOfObjectName=dests[i].getObjectName().getCanonicalName();
    serviceComponentOfObjectName=serviceComponentOfObjectName.substring(serviceComponentOfObjectName.indexOf('_') + 1,serviceComponentOfObjectName.indexOf(",",serviceComponentOfObjectName.indexOf('_')));
    log.debug("Service name component of ObjectName is: " + serviceComponentOfObjectName);
    if (serviceComponentOfObjectName.equals(serviceName)) {
      log.debug("find serviceName " + serviceName + " in Queues");
      return true;
    }
  }
  log.trace("did not find serviceName " + serviceName);
  return false;
}
 

Example 26

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

Source file: BoneCP.java

  17 
vote

/** 
 * Initialises JMX stuff.
 * @param doRegister if true, perform registration, if false unregister
 */
protected void registerUnregisterJMX(boolean doRegister){
  if (this.mbs == null) {
    this.mbs=ManagementFactory.getPlatformMBeanServer();
  }
  try {
    String suffix="";
    if (this.config.getPoolName() != null) {
      suffix="-" + this.config.getPoolName();
    }
    ObjectName name=new ObjectName(MBEAN_BONECP + suffix);
    ObjectName configname=new ObjectName(MBEAN_CONFIG + suffix);
    if (doRegister) {
      if (!this.mbs.isRegistered(name)) {
        this.mbs.registerMBean(this.statistics,name);
      }
      if (!this.mbs.isRegistered(configname)) {
        this.mbs.registerMBean(this.config,configname);
      }
    }
 else {
      if (this.mbs.isRegistered(name)) {
        this.mbs.unregisterMBean(name);
      }
      if (this.mbs.isRegistered(configname)) {
        this.mbs.unregisterMBean(configname);
      }
    }
  }
 catch (  Exception e) {
    logger.error("Unable to start/stop JMX",e);
  }
}
 

Example 27

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

Source file: JBoss7CamelContextConfiguration.java

  17 
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 28

From project cloudify, under directory /USM/src/main/java/org/cloudifysource/usm/jmx/.

Source file: JmxGenericClient.java

  17 
vote

protected void handleJMXBean(final ArrayList<JmxAttribute> resultList,final MBeanServerConnection mbsc,final JmxBeanAttributes t) throws MalformedObjectNameException {
  final ObjectName beanName=new ObjectName(t.getObjectName());
  final String[] attributeNames=t.getAttributeNames();
  try {
    final AttributeList vals=mbsc.getAttributes(beanName,attributeNames);
    @SuppressWarnings("rawtypes") final Iterator it=vals.iterator();
    while (it.hasNext()) {
      final Attribute att=(Attribute)it.next();
      if (att.getValue() instanceof Exception) {
        logger.log(Level.WARNING,"Failed to read JMX attribute: " + att.getName() + " in bean: "+ t.getObjectName(),att.getValue());
      }
 else {
        final JmxAttribute result=t.setValueAndReturnAttribute(att.getName(),att.getValue());
        resultList.add(result);
      }
    }
  }
 catch (  final Exception e) {
    if (logger.isLoggable(Level.WARNING)) {
      logger.warning("Failed to read Attributes for JMX Bean: " + t + ": "+ e.getMessage());
    }
    if (logger.isLoggable(Level.FINE)) {
      logger.log(Level.FINE,"Failed to read Attributes for JMX Bean: " + t,e);
    }
  }
}
 

Example 29

From project commons-dbcp-jmx, under directory /jdbc3/src/test/java/org/apache/commons/dbcp/.

Source file: ManagedBasicDataSourceTest.java

  17 
vote

/** 
 * Assert configuration of an attribute is taken into account and has the same value when queried directly or through the MBean.
 * @param attributeProperty      the property to use to configure the attribute.
 * @param attributePropertyValue the value to use for the attribute.
 * @param attributeName          the name of the attribute in the MBean.
 * @param attributeGetterName    the name of the getter method for the attribute.
 * @throws Exception should not happen.
 */
@Test(dataProvider="testConfigurableAttributeProvider") public void testConfigurableAttribute(String attributeProperty,Object attributePropertyValue,String attributeName,String attributeGetterName) throws Exception {
  final Properties testDataSourceProperties=new Properties();
  testDataSourceProperties.put(attributeProperty,String.valueOf(attributePropertyValue));
  final ManagedBasicDataSource testDataSource=(ManagedBasicDataSource)ManagedBasicDataSourceFactory.createDataSource(testDataSourceProperties);
  final Object attributeValue=getMBeanServerConnection().getAttribute(new ObjectName(testDataSource.getMBeanName()),attributeName);
  assertTrue((ManagedBasicDataSource.class.getMethod(attributeGetterName).invoke(testDataSource)).equals(attributeValue));
}
 

Example 30

From project dcm4che, under directory /dcm4che-servlet/src/main/java/org/dcm4che/sample/servlet/.

Source file: EchoSCPServlet.java

  17 
vote

@Override public void init(ServletConfig config) throws ServletException {
  super.init(config);
  try {
    dicomConfig=(DicomConfiguration)Class.forName(config.getInitParameter("dicomConfigurationClass"),false,Thread.currentThread().getContextClassLoader()).newInstance();
    echoSCP=new EchoSCP(dicomConfig,config.getInitParameter("deviceName"));
    echoSCP.start();
    mbean=ManagementFactory.getPlatformMBeanServer().registerMBean(echoSCP,new ObjectName(config.getInitParameter("jmxName")));
  }
 catch (  Exception e) {
    destroy();
    throw new ServletException(e);
  }
}
 

Example 31

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

Source file: AbstractDynamicMBean.java

  17 
vote

/** 
 * Performs cleanup for deregistering this MBean. Default implementation unregisters MBean instances which are registered using  {@link #registerMBean(Object mbean,ObjectName objectName)}.
 */
public void preDeregister(){
  getLogger().debug("preDeregister called.");
  Enumeration iterator=mbeanList.elements();
  while (iterator.hasMoreElements()) {
    ObjectName name=(ObjectName)iterator.nextElement();
    try {
      server.unregisterMBean(name);
    }
 catch (    InstanceNotFoundException e) {
      getLogger().warn("Missing MBean " + name.getCanonicalName());
    }
catch (    MBeanRegistrationException e) {
      getLogger().warn("Failed unregistering " + name.getCanonicalName());
    }
  }
}
 

Example 32

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

Source file: JMXPlatformImplTest.java

  17 
vote

@Test public void testRegister() throws Exception {
  assertFalse(mbs.isRegistered(new ObjectName(DOZER_ADMIN_CONTROLLER)));
  platform.registerMBean(DOZER_ADMIN_CONTROLLER,new DozerAdminController());
  assertTrue(mbs.isRegistered(new ObjectName(DOZER_ADMIN_CONTROLLER)));
  platform.unregisterMBean(DOZER_ADMIN_CONTROLLER);
  assertFalse(mbs.isRegistered(new ObjectName(DOZER_ADMIN_CONTROLLER)));
}
 

Example 33

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 34

From project eik, under directory /plugins/info.evanchik.eclipse.karaf.workbench/src/main/java/info/evanchik/eclipse/karaf/workbench/ui/editor/.

Source file: KarafPlatformGeneralFormPage.java

  17 
vote

/** 
 * @param objectName
 * @return
 */
private ObjectName createObjectName(final String objectName){
  try {
    return new ObjectName(objectName);
  }
 catch (  final Exception e) {
    throw new AssertionError(e);
  }
}
 

Example 35

From project en4j, under directory /NBPlatformApp/NoteRepositoryJDBM/src/main/java/com/rubenlaguna/en4j/noterepositoryjdbm/.

Source file: Installer.java

  17 
vote

@Override public void restored(){
  try {
    ManagementFactory.getPlatformMBeanServer().registerMBean(mbean,new ObjectName("com.rubenlaguna.en4j.noterepositoryjdbm:type=JdbmMgmt"));
  }
 catch (  JMException ex) {
  }
}
 

Example 36

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 37

From project flume, under directory /flume-ng-core/src/main/java/org/apache/flume/instrumentation/.

Source file: MonitoredCounterGroup.java

  17 
vote

protected MonitoredCounterGroup(Type type,String name,String... attrs){
  this.type=type;
  this.name=name;
  Map<String,AtomicLong> counterInitMap=new HashMap<String,AtomicLong>();
  for (  String attribute : attrs) {
    counterInitMap.put(attribute,new AtomicLong(0L));
  }
  counterMap=Collections.unmodifiableMap(counterInitMap);
  startTime=new AtomicLong(0L);
  stopTime=new AtomicLong(0L);
  try {
    ObjectName objName=new ObjectName("org.apache.flume." + type.name().toLowerCase() + ":type="+ this.name);
    ManagementFactory.getPlatformMBeanServer().registerMBean(this,objName);
    LOG.info("Monitoried counter group for type: " + type + ", name: "+ name+ ", registered successfully.");
  }
 catch (  Exception ex) {
    LOG.error("Failed to register monitored counter group for type: " + type + ", name: "+ name,ex);
  }
}
 

Example 38

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 39

From project gecko, under directory /src/main/java/com/taobao/gecko/core/util/.

Source file: MyMBeanServer.java

  17 
vote

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

Example 40

From project geronimo-xbean, under directory /xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/.

Source file: ObjectNameEditor.java

  17 
vote

public void setAsText(String text) throws IllegalArgumentException {
  try {
    setValue(new ObjectName(text));
  }
 catch (  MalformedObjectNameException e) {
    throw new IllegalArgumentException("Could not convert ObjectName for " + text + ": "+ e.getMessage());
  }
}
 

Example 41

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

Source file: TestIdxRegion.java

  17 
vote

/** 
 * Verifies the jmx bean for the region.
 * @param region the refion to verify.
 */
private static void verifyMBean(IdxRegion region) throws Exception {
  final MBeanServer mbs=ManagementFactory.getPlatformMBeanServer();
  ObjectName objectName=IdxRegionMBeanImpl.generateObjectName(region.getRegionInfo());
  MBeanInfo mbeanInfo=mbs.getMBeanInfo(objectName);
  for (  MBeanAttributeInfo aInfo : mbeanInfo.getAttributes()) {
    Object value=mbs.getAttribute(objectName,aInfo.getName());
    if (aInfo.isWritable()) {
      mbs.setAttribute(objectName,new Attribute(aInfo.getName(),value));
    }
  }
  for (  MBeanOperationInfo oInfo : mbeanInfo.getOperations()) {
    if (oInfo.getSignature().length == 0) {
      mbs.invoke(objectName,oInfo.getName(),new Object[]{},new String[]{});
    }
 else {
      LOG.warn("Did not test operation " + oInfo.getName());
    }
  }
}
 

Example 42

From project infinispan-arquillian-container, under directory /infinispan-container-managed/src/main/java/org/infinispan/arquillian/container/managed/.

Source file: InfinispanContainer.java

  17 
vote

private boolean isServerModuleStarted(String moduleName){
  final String serverModule="org.infinispan:type=Server,name=" + moduleName + ",component=Transport";
  try {
    Set<ObjectInstance> mBeans=(Set<ObjectInstance>)provider.getConnection().queryMBeans(new ObjectName(serverModule),null);
    return mBeans.size() == 1 ? true : false;
  }
 catch (  Exception e) {
    return false;
  }
}
 

Example 43

From project azkaban, under directory /azkaban/src/java/azkaban/app/.

Source file: AzkabanApplication.java

  16 
vote

private void configureMBeanServer(){
  logger.info("Registering MBeans...");
  mbeanServer=ManagementFactory.getPlatformMBeanServer();
  try {
    jobRefresherName=new ObjectName("azkaban.app.jmx.RefreshJobs:name=jobRefresher");
    jobSchedulerName=new ObjectName("azkaban.app.jmx.jobScheduler:name=jobScheduler");
    mbeanServer.registerMBean(new RefreshJobs(this),jobRefresherName);
    logger.info("Bean " + jobRefresherName.getCanonicalName() + " registered.");
    mbeanServer.registerMBean(new JobScheduler(_schedulerManager,_jobManager),jobSchedulerName);
    logger.info("Bean " + jobSchedulerName.getCanonicalName() + " registered.");
  }
 catch (  Exception e) {
    logger.error("Failed to configure MBeanServer",e);
  }
}
 

Example 44

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

Source file: RemoteWorkbenchAgent.java

  16 
vote

private final static void createServerUrl(final int startPort){
  if (serverUrl != null)   return;
  try {
    String hostName=System.getProperty("org.dawb.workbench.jmx.host.name");
    if (hostName == null)     hostName=InetAddress.getLocalHost().getHostName();
    if (hostName == null)     hostName=InetAddress.getLocalHost().getHostAddress();
    if (hostName == null)     hostName="localhost";
    currentPort=getFreePort(startPort);
    serverUrl=new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostName + ":"+ currentPort+ "/workbench");
    REMOTE_WORKBENCH=new ObjectName(RemoteWorkbenchManager.class.getPackage().getName() + ":type=RemoteWorkbench");
  }
 catch (  Exception e) {
    logger.error("Cannot create ObjectName for remotemanager",e);
  }
  logger.debug("Workbench URI: " + serverUrl.getURLPath());
}
 

Example 45

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

Source file: Manager.java

  16 
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 46

From project enterprise, under directory /ha/src/test/java/jmx/.

Source file: JmxDocsTest.java

  15 
vote

private void writeDetailsToFile(String id,ObjectName objectName,ObjectInstance bean,MBeanInfo info,String description) throws IOException {
  StringBuilder beanInfo=new StringBuilder(2048);
  String name=objectName.getKeyProperty(BEAN_NAME);
  String name0=objectName.getKeyProperty(BEAN_NAME0);
  if (name0 != null) {
    name+="/" + name0;
  }
  MBeanAttributeInfo[] attributes=info.getAttributes();
  if (attributes.length > 0) {
    beanInfo.append("[[").append(id).append("]]\n" + ".MBean ").append(name).append(" (").append(bean.getClassName()).append(") Attributes\n");
    writeAttributesTable(description,beanInfo,attributes,false);
    writeAttributesTable(description,beanInfo,attributes,true);
    beanInfo.append("\n");
  }
  MBeanOperationInfo[] operations=info.getOperations();
  if (operations.length > 0) {
    beanInfo.append(".MBean ").append(name).append(" (").append(bean.getClassName()).append(") Operations\n");
    writeOperationsTable(beanInfo,operations,false);
    writeOperationsTable(beanInfo,operations,true);
    beanInfo.append("\n");
  }
  if (beanInfo.length() > 0) {
    Writer fw=null;
    try {
      fw=AsciiDocGenerator.getFW("target/docs/ops",id);
      fw.write(beanInfo.toString());
    }
  finally {
      if (fw != null) {
        fw.close();
      }
    }
  }
}
 

Example 47

From project glassfish-asadmin-api, under directory /src/main/java/se/glassfish/asadmin/api/command/.

Source file: JMXQueryCommand.java

  15 
vote

public JMXQueryCommand(int port,String host,String username,String password,ObjectName query){
  this.port=port;
  this.host=host;
  this.username=username;
  this.password=password;
  this.query=query;
}
 

Example 48

From project gxa, under directory /atlas-web/src/main/java/uk/ac/ebi/gxa/jmx/.

Source file: PerInstanceNamingStrategy.java

  15 
vote

public ObjectName getObjectName(Object o,String s) throws MalformedObjectNameException {
  Hashtable<String,String> table=new Hashtable<String,String>();
  table.put("name",s);
  table.put("instance",contextId);
  return ObjectName.getInstance(domain,table);
}