Package javax.management

Examples of javax.management.MBeanServerConnection


   }

   public MBeanServerConnection getServer() throws NamingException
   {
      InitialContext iniCtx = new InitialContext();
      MBeanServerConnection server = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
      return server;
   }
View Full Code Here


      //{
      //   throw new CommandException("Missing object name");
      //}
      //ObjectName target = super.createObjectName(args[0]);

      MBeanServerConnection server = super.getMBeanServer();
      PrintWriter out = context.getWriter();
     
      Set jsr77Domains = locateJSR77Domains(server);
      for (Iterator i = jsr77Domains.iterator(); i.hasNext(); )
      {
View Full Code Here

      log.debug("object names: " + names);

      if (names.size() == 0)
         throw new CommandException("At least one object name is required");

      MBeanServerConnection server = getMBeanServer();

      Iterator iter = names.iterator();
      while (iter.hasNext())
      {
         ObjectName name = (ObjectName)iter.next();
         server.unregisterMBean(name);
      }
      closeServer();
   }
View Full Code Here

   private void invoke(final ObjectName name)
      throws Exception
   {
      log.debug("Invoke " + name);

      MBeanServerConnection server = getMBeanServer();
     
      // get mbean info for this mbean
      MBeanInfo info = server.getMBeanInfo(name);
     
      // does it even have an operation of this name?
      MBeanOperationInfo[] ops = info.getOperations();
      MBeanOp inputOp = new MBeanOp(opName, opArgs.size());
      MBeanOp matchOp = null;
      ArrayList opList = new ArrayList();
      for (int i = 0; i < ops.length; i++)
      {
         MBeanOperationInfo opInfo = ops[i];
         MBeanOp op = new MBeanOp(opInfo.getName(), opInfo.getSignature());
         if (inputOp.equals(op) == true)
         {
            matchOp = op;
            break;
         }
         opList.add(op);
      }

      if (matchOp == null)
      {
         // If there was not explicit match on type, look for a match on arg count
         OpCountComparator comparator = new OpCountComparator();
         Collections.sort(opList, comparator);
         int match = Collections.binarySearch(opList, inputOp, comparator);
         if (match >= 0)
         {
            // Validate that the match op equates to the input op
            matchOp = (MBeanOp) opList.get(match);
            match = comparator.compare(matchOp, inputOp);
            if (match != 0)
            {
               throw new CommandException("MBean has no such operation named '" +
                  opName + "' with signature compatible with: " + opArgs);
            }
         }
         else
         {
            throw new CommandException("MBean has no such operation named '" +
               opName + "' with signature compatible with: " + opArgs);
         }
      }
     
      // convert parameters with PropertyEditor
      int count = matchOp.getArgCount();
      Object[] params = new Object[count];
      for (int i = 0; i < count; i++)
      {
         String argType = matchOp.getArgType(i);
         PropertyEditor editor = PropertyEditors.getEditor(argType);
         editor.setAsText((String) opArgs.get(i));
         params[i] = editor.getValue();
      }
      log.debug("Using params: " + Strings.join(params, ","));
     
      // invoke the operation
      Object result = server.invoke(name, opName, params, matchOp.getSignature());
      log.debug("Raw result: " + result);

      if (!context.isQuiet())
      {
         // Translate the result to text
View Full Code Here

      processArguments(args);

      if (objectName == null)
         throw new CommandException("Missing object name");

      MBeanServerConnection server = getMBeanServer();
      MBeanInfo mbeanInfo = server.getMBeanInfo(objectName);
      MBeanAttributeInfo[] attrInfo = mbeanInfo.getAttributes();
      MBeanOperationInfo[] opInfo = mbeanInfo.getOperations();

      PrintWriter out = context.getWriter();
      out.println("Description: "+mbeanInfo.getDescription());
View Full Code Here

      if (objectName == null)
         throw new CommandException("Missing object name");

      log.debug("attribute names: " + attributeNames);

      MBeanServerConnection server = getMBeanServer();
      if (attributeNames.size() == 0)
      {
         // Display all readable attributes
         attributeNames.clear();
         MBeanInfo info = server.getMBeanInfo(objectName);
         MBeanAttributeInfo[] attrInfos = info.getAttributes();
         for (int a = 0; a < attrInfos.length; a++)
         {
            MBeanAttributeInfo attrInfo = attrInfos[a];
            if (attrInfo.isReadable())
               attributeNames.add(attrInfo.getName());
         }
      }

      String[] names = new String[attributeNames.size()];
      attributeNames.toArray(names);
      log.debug("as string[]: " + Strings.join(names, ","));

      AttributeList attrList = server.getAttributes(objectName, names);
      log.debug("attribute list: " + attrList);

      if (attrList.size() == 0)
      {
         throw new CommandException("No matching attributes");
View Full Code Here

    log.debug("attribute names: " + attributeNames);
    if (attributeNames.size() != 2 )
    {
      throw new CommandException("Wrong number of arguments");
    }
    MBeanServerConnection server = getMBeanServer();

    MBeanInfo info = server.getMBeanInfo(objectName);
   
    MBeanAttributeInfo[] attrs = info.getAttributes();
   
    MBeanAttributeInfo attr=null;

    boolean found = false;
    for (int i=0;i < attrs.length ; i++ )
    {     
      if (attrs[i].getName().equals(theAttr) &&
        attrs[i].isWritable()) {
       
          found=true;
          attr= attrs[i];
          break;
        }
    }
   
    if (found == false)
    {
     
      throw new CommandException("No matching attribute found");
    }
    else
    {
      Object oVal = convert(theVal,attr.getType());
      Attribute at = new Attribute(theAttr,oVal);
      server.setAttribute(objectName,at);
     
      // read the attribute back from the server
      if (!context.isQuiet())
      {
        PrintWriter out = context.getWriter();
        Object nat = server.getAttribute(objectName,theAttr);
        if (nat==null)
          out.println("null");
        else
          if (prefix)
            out.print(theAttr+"=");
View Full Code Here

  
   protected ObjectName[] queryMBeans(final String query)
      throws Exception
   {
      // query the mbean server
      MBeanServerConnection server = getMBeanServer();
     
      Set matches = server.queryNames(new ObjectName(query), null);
      log.debug("Query matches: " + matches);

      if (matches.size() == 0) {
         throw new CommandException("No MBean matches for query: " + query);
      }
View Full Code Here

   public void execute(String[] args) throws Exception
   {
      processArguments(args);
     
      PrintWriter out = context.getWriter();
      MBeanServerConnection server = getMBeanServer();

      // mode should be valid, either invalid arg or no arg
     
      switch (mode)
      {
         case DEFAULT_DOMAIN:
            out.println(server.getDefaultDomain());
            break;

         case MBEAN_COUNT:
            out.println(server.getMBeanCount());
            break;

         case LIST_NAMES:
            ObjectName all = new ObjectName("*:*");
            Set names = server.queryNames(all, null);
            Iterator iter = names.iterator();
            while( iter.hasNext() )
               out.println(iter.next());
            break;

View Full Code Here

      processArguments(args);
     
      if (className == null)
         throw new CommandException("Missing class name");

      MBeanServerConnection server = getMBeanServer();

      ObjectInstance obj;

      if (loaderName == null) {
         obj = server.createMBean(className, objectName);
      }
      else {
         obj = server.createMBean(className, objectName, loaderName);
      }

      if (!context.isQuiet()) {
         PrintWriter out = context.getWriter();
         out.println(obj.getObjectName());
View Full Code Here

TOP

Related Classes of javax.management.MBeanServerConnection

Copyright © 2018 www.massapicom. 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.