User: juhalindfors
  Date: 02/01/23 14:00:04

  Added:       src/main/org/jboss/mx/util AgentID.java
  Log:
  Used for creating agent IDs and retrieving the server delegate ID.
  
  Revision  Changes    Path
  1.1                  jmx/src/main/org/jboss/mx/util/AgentID.java
  
  Index: AgentID.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.mx.util;
  
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  import java.util.Date;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  import org.jboss.mx.server.ServerConstants;
  
  /**
   * Utility class for creating JMX agent identifiers. Also contains the
   * helper method for retrieving the <tt>AgentID</tt> of an existing MBean server
   * instance.
   *
   * @see javax.management.MBeanServerDelegateMBean
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
   * @version $Revision: 1.1 $
   *   
   */
  public class AgentID 
     implements ServerConstants
  {
  
     // Static ----------------------------------------------------
     private static int idSequence = 1;
  
     public static String create()
     {
        String ipAddress = null;
        
        try
        {
           ipAddress = InetAddress.getLocalHost().getHostAddress();
        }
        catch (UnknownHostException e) 
        {
           ipAddress = "127.0.0.1";
        }
        
        return ipAddress + "/" + System.currentTimeMillis() + "/" + (idSequence++);    
           
     }
     
     public static String get(MBeanServer server)
     {
        try 
        {
           ObjectName name = new ObjectName(MBEAN_SERVER_DELEGATE);
           String agentID = (String)server.getAttribute(name, "MBeanServerId");   
        
           return agentID;
        }
        catch (Throwable t)
        {
           throw new Error("Cannot find the MBean server delegate: " + t.toString());
        }
     }
  }
        
  
  
  
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to