commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-commons/modeler/src/java/org/apache/commons/modeler/mbeans MBeanProxy.java
Date Mon, 07 Apr 2003 07:15:27 GMT
costin      2003/04/07 00:15:27

  Added:       modeler/src/java/org/apache/commons/modeler/mbeans
                        MBeanProxy.java
  Log:
  Based on ModJkMX, a small proxy to support simple remote mbeans.
  The communication uses manifest format - very easy to parse, standard and
  "good enough" for this purpose.
  
  Revision  Changes    Path
  1.1                  jakarta-commons/modeler/src/java/org/apache/commons/modeler/mbeans/MBeanProxy.java
  
  Index: MBeanProxy.java
  ===================================================================
  package org.apache.commons.modeler.mbeans;
  
  import org.apache.commons.modeler.BaseModelMBean;
  import org.apache.commons.modeler.ManagedBean;
  import org.apache.commons.modeler.AttributeInfo;
  import org.apache.commons.modeler.OperationInfo;
  import org.apache.commons.modeler.Registry;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import java.util.List;
  import java.util.HashMap;
  import java.io.InputStream;
  import javax.management.ObjectName;
  import javax.management.MBeanServer;
  import javax.management.AttributeNotFoundException;
  import javax.management.MBeanException;
  import javax.management.ReflectionException;
  import javax.management.Attribute;
  
  /** Use the same metadata, except that we replace the attribute
   * get/set methods.
   */
  class MBeanProxy extends BaseModelMBean {
      private static Log log = LogFactory.getLog(MBeanProxy.class);
  
      HashMap atts=new HashMap();
  
      SimpleRemoteConnector jkmx;
  
      public MBeanProxy(SimpleRemoteConnector jkmx, String code) throws Exception {
          this.jkmx=jkmx;
          initModelInfo(code);
      }
  
      /** Called by the connector - will update the value when a chunk of
       * data is received
       */
      protected void update( String name, String val ) {
          if( log.isDebugEnabled() )
              log.debug( "Updating " + oname + " " + name + " " + val);
          // XXX Conversions !!!
          atts.put( name, val);
      }
  
      public Object getAttribute(String name)
          throws AttributeNotFoundException, MBeanException,
              ReflectionException
      {
          // If we're stale - refresh values
          jkmx.refresh();
          return atts.get(name);
      }
  
      public void setAttribute(Attribute attribute)
          throws AttributeNotFoundException, MBeanException,
          ReflectionException
      {
          try {
              jkmx.setAttribute(oname, attribute);
          } catch( Exception ex ) {
              throw new MBeanException(ex);
          }
      }
  
      public Object invoke(String name, Object params[], String signature[])
          throws MBeanException, ReflectionException
      {
          try {
              jkmx.invoke(oname, name, params, signature);
          } catch( Exception ex ) {
              throw new MBeanException(ex);
          }
          return null;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message