Examples of MBeanServer


Examples of javax.management.MBeanServer

        long threadID = ServletRequestUtils.getLongParameter(request, "id", -1);
        String threadName = ServletRequestUtils.getStringParameter(request, "name", null);

        List stack = null;
        MBeanServer mBeanServer = new Registry().getMBeanServer();
        ObjectName threadingOName = new ObjectName("java.lang:type=Threading");


        if (threadID == -1 && threadName != null) {
            // find thread by name
            long[] allIds = (long[]) mBeanServer.getAttribute(threadingOName, "AllThreadIds");
            for (int i = 0; i < allIds.length; i++) {
                CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                        new Object[]{new Long(allIds[i])}, new String[] {"long"});
                String name = JmxTools.getStringAttr(cd, "threadName");
                if (threadName.equals(name)) {
                    threadID = allIds[i];
                    break;
                }
            }
        }

        if (mBeanServer.queryMBeans(threadingOName, null) != null && threadID != -1) {

            CompositeData cd = (CompositeData) mBeanServer.invoke(threadingOName, "getThreadInfo",
                    new Object[]{new Long(threadID), new Integer(stackElementCount)}, new String[] {"long", "int"});
            if (cd != null) {
                CompositeData[] elements = (CompositeData[]) cd.get("stackTrace");
                threadName = JmxTools.getStringAttr(cd, "threadName");
View Full Code Here

Examples of javax.management.MBeanServer

        MBeanInfo info;
        ObjectName name;
        Connection conn;
        Statement stat;

        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

        conn = getConnection("mem:jmx;jmx=true");
        stat = conn.createStatement();

        name = new ObjectName("org.h2:name=JMX,path=mem_jmx");
        info = mbeanServer.getMBeanInfo(name);
        assertEquals("0", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
        // cache size is ignored for in-memory databases
        mbeanServer.setAttribute(name, new Attribute("CacheSizeMax", 1));
        assertEquals("0", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
        assertEquals("0", mbeanServer.getAttribute(name, "CacheSize").toString());
        assertEquals("false", mbeanServer.getAttribute(name, "Exclusive").toString());
        assertEquals("0", mbeanServer.getAttribute(name, "FileSize").toString());
        assertEquals("0", mbeanServer.getAttribute(name, "FileReadCount").toString());
        assertEquals("0", mbeanServer.getAttribute(name, "FileWriteCount").toString());
        assertEquals("0", mbeanServer.getAttribute(name, "FileWriteCountTotal").toString());
        assertEquals("0", mbeanServer.getAttribute(name, "LogMode").toString());
        // ignored for in-memory databases
        mbeanServer.setAttribute(name, new Attribute("LogMode", 1));
        assertEquals("0", mbeanServer.getAttribute(name, "LogMode").toString());
        assertEquals("REGULAR", mbeanServer.getAttribute(name, "Mode").toString());
        assertEquals("false", mbeanServer.getAttribute(name, "MultiThreaded").toString());
        assertEquals("false", mbeanServer.getAttribute(name, "Mvcc").toString());
        assertEquals("false", mbeanServer.getAttribute(name, "ReadOnly").toString());
        assertEquals("1", mbeanServer.getAttribute(name, "TraceLevel").toString());
        mbeanServer.setAttribute(name, new Attribute("TraceLevel", 0));
        assertEquals("0", mbeanServer.getAttribute(name, "TraceLevel").toString());
        assertTrue(mbeanServer.getAttribute(name, "Version").toString().startsWith("1."));
        assertEquals(14, info.getAttributes().length);
        result = mbeanServer.invoke(name, "listSettings", null, null).toString();
        assertTrue(result.indexOf("ANALYZE_AUTO") >= 0);

        conn.setAutoCommit(false);
        stat.execute("create table test(id int)");
        stat.execute("insert into test values(1)");

        result = mbeanServer.invoke(name, "listSessions", null, null).toString();
        assertTrue(result.indexOf("session id") >= 0);
        assertTrue(result.indexOf("write lock") >= 0);

        assertEquals(2, info.getOperations().length);
        assertTrue(info.getDescription().indexOf("database") >= 0);
        attrMap = New.hashMap();
        for (MBeanAttributeInfo a : info.getAttributes()) {
            attrMap.put(a.getName(), a);
        }
        assertTrue(attrMap.get("CacheSize").getDescription().indexOf("KB") >= 0);
        opMap = New.hashMap();
        for (MBeanOperationInfo o : info.getOperations()) {
            opMap.put(o.getName(), o);
        }
        assertTrue(opMap.get("listSessions").getDescription().indexOf("lock") >= 0);
        assertEquals(MBeanOperationInfo.INFO, opMap.get("listSessions").getImpact());

        conn.close();

        conn = getConnection("jmx;jmx=true");

        name = new ObjectName("org.h2:name=JMX,*");
        Set set = mbeanServer.queryNames(name, null);
        name = (ObjectName) set.iterator().next();

        assertEquals("16384", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
        mbeanServer.setAttribute(name, new Attribute("CacheSizeMax", 1));
        assertEquals("1", mbeanServer.getAttribute(name, "CacheSizeMax").toString());
        assertTrue(0 < (Integer) mbeanServer.getAttribute(name, "CacheSize"));
        assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileSize"));
        assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileReadCount"));
        assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileWriteCount"));
        assertTrue(0 < (Long) mbeanServer.getAttribute(name, "FileWriteCountTotal"));
        mbeanServer.setAttribute(name, new Attribute("LogMode", 0));
        assertEquals("0", mbeanServer.getAttribute(name, "LogMode").toString());

        conn.close();

    }
View Full Code Here

Examples of javax.management.MBeanServer

    ObjectName mbeanObjectName = new ObjectName(name);
    unregister(name, mbeanObjectName);
  }
 
  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);
    }
  }
View Full Code Here

Examples of javax.management.MBeanServer

      log.info("JMX MBean instance exists, unable to overwrite [{}].", name);
    }
  }

  private void unregister(String name, ObjectName mbeanObjectName) throws MBeanRegistrationException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    boolean isMBeanRegistered = mbs.isRegistered(mbeanObjectName);
    if (isMBeanRegistered) {
      log.info("Unregistering existing Dozer JMX MBean [{}].", name);
      try {
        mbs.unregisterMBean(mbeanObjectName);
      } catch (InstanceNotFoundException e) {
        log.info("JMX MBean not found to unregister [{}].", name);
      }
    }
  }
View Full Code Here

Examples of javax.management.MBeanServer

    }
  }
  public static void main(String args[]){
    try {
      MBeanUtil mu = new MBeanUtil();
      MBeanServer mbs = mu.createRemoteMBeanServer("localhost",9999);
      mu.createServiceMBean("Contract");
      System.out.println("Server is up and Running press any key to exit");
      mu.recordFailedRequest("Contract");
      mu.recordSuccessfulRequest("Contract");
      mu.setLastResponseTime("Contract",new Long(300));
View Full Code Here

Examples of javax.management.MBeanServer

    /*
     * Register MBeans
     */
    try {
      MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
      ObjectName name = new ObjectName("xBus:mbean=Administrator");
      Administrator mbean = new Administrator();
      mbs.registerMBean(mbean, name);
    } catch (Exception e) {
      throw new XException(Constants.LOCATION_INTERN,
          Constants.LAYER_ADMIN, Constants.PACKAGE_ADMIN_JMX, "0", e);
    }

View Full Code Here

Examples of javax.management.MBeanServer

   private final HttpAdaptor instantiateAdaptor(Global global) throws Exception {
     
      int port = getInt("port", 9999);
      String host = get("host", "0.0.0.0");
      String adaptorName = get("adaptorName", "HttpAdaptorMX4J");
      MBeanServer server = global.getJmxWrapper().getMBeanServer();
      HttpAdaptor adapter = new HttpAdaptor();
      this.name = new ObjectName("Adaptor:name=" + adaptorName);
      server.registerMBean(adapter, name);
      adapter.setHost(host);
      adapter.setPort(port);
      this.authMethod = get("authenticationMethod", null);
      log.info("Authentication Method is '" + this.authMethod + "'");
      if (this.authMethod != null) {
         this.authMethod = this.authMethod.trim();
         if ("basic".equals(this.authMethod))
            adapter.setAuthenticationMethod(this.authMethod);
         else
            log.warning("Authentication method '" + authMethod + "' not recognized, will switch to 'basic'");
         log.info("Authentication Method is '" + this.authMethod + "'");
         Map users = InfoHelper.getPropertiesStartingWith("replication.monitor.user.", this, null);
         if (users != null && users.size() > 0) {
            Iterator iter = users.entrySet().iterator();
            while (iter.hasNext()) {
               Map.Entry entry = (Map.Entry)iter.next();
               String name = (String)entry.getKey();
               String val = (String)entry.getValue();
               log.fine("name='" + name + "' value='" + val + "'");
               int pos = val.indexOf(':');
               String pwd = null;
               String roles = USER_ROLE;
               if (pos > -1) {
                  pwd = val.substring(0, pos);
                  roles = val.substring(pos+1);
               }
               else
                  pwd = val;
               log.fine("registering monitor user '" + name + "' having roles : " + roles + "'");
               adapter.addAuthorization(name, pwd);
               this.roles.put(name, roles);
            }
         }
         else
            log.info("No Users found for the monitor");
      }
     
      String xsltProcessor = get("xsltProcessor", null);
      ObjectName processorName = null;
      if (xsltProcessor != null) {

         ContextNode contextNode = new ContextNode(ContextNode.CONTRIB_MARKER_TAG, "jmx" + ContextNode.SEP + xsltProcessor,
               this.global.getContextNode());
         processorName = new ObjectName(JmxWrapper.getObjectNameLiteral(this.global, contextNode));
        
         // XSLTProcessor processor = new XSLTProcessor();
         ContribXsltProcessor processor = new ContribXsltProcessor(this.roles, this.authMethod);
        
         server.registerMBean(processor, processorName);
        
         // set it to use a dir
         String xsltPath = get("xsltPath", null); // can be a directory or a jar file
         String xsltPathInJar = null;
View Full Code Here

Examples of javax.management.MBeanServer

      log.info("The adaptor '" + adaptorName + "' is running. You can access it at 'http://" + host + ":" + port + "'");
      return adapter;
   }

   private final void stopAdaptor() throws Exception {
      MBeanServer server = this.global.getJmxWrapper().getMBeanServer();
      server.unregisterMBean(this.name);
      this.adaptor.stop();
   }
View Full Code Here

Examples of javax.management.MBeanServer

        implementor = new GreeterImpl();
        address = "http://localhost:9000/SoapContext/SoapPort";
        Endpoint.publish(address, implementor);
        //register to the bus MBServer       
        Bus bus = Bus.getCurrent();
        MBeanServer mbserver = bus.getInstrumentationManager().getMBeanServer();
        ObjectName name = new ObjectName("org.objectweb.celtix.instrumentation:type=ServerMBean,Bus="
                        + bus.getBusID() + ",name=ServerMBean");
        mbserver.registerMBean(this, name);
    }
View Full Code Here

Examples of javax.management.MBeanServer


public class MBServerConnectorTest extends  TestCase {
    public void testMBServerConnector() {
        MBServerConnectorFactory mcf;   
        MBeanServer mbs;       
        mbs = MBeanServerFactory.createMBeanServer("test");           
        mcf = MBServerConnectorFactory.getInstance();
        mcf.setMBeanServer(mbs);
        mcf.setThreaded(true);
        mcf.setDaemon(true);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.