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/modules MbeansSourceMBean.java MbeansSource.java ModelerSource.java
Date Mon, 14 Apr 2003 01:01:55 GMT
costin      2003/04/13 18:01:55

  Modified:    modeler/src/java/org/apache/commons/modeler/modules
                        MbeansSource.java ModelerSource.java
  Added:       modeler/src/java/org/apache/commons/modeler/modules
                        MbeansSourceMBean.java
  Log:
  Make the modeler source a proper mbean, so it can be registered and
  used independently.
  
  This is still very experimental and incomplete.
  
  Revision  Changes    Path
  1.12      +36 -5     jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansSource.java
  
  Index: MbeansSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansSource.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MbeansSource.java	13 Apr 2003 17:11:56 -0000	1.11
  +++ MbeansSource.java	14 Apr 2003 01:01:55 -0000	1.12
  @@ -13,6 +13,9 @@
   import java.io.InputStream;
   import java.io.FileOutputStream;
   import java.io.FileNotFoundException;
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.IOException;
   import java.net.URL;
   import java.util.ArrayList;
   import java.util.List;
  @@ -29,13 +32,11 @@
    * XXX add a special attribute to reference the loader mbean,
    * XXX figure out how to deal with private loaders
    */
  -public class MbeansSource extends ModelerSource
  +public class MbeansSource extends ModelerSource implements MbeansSourceMBean
   {
       private static Log log = LogFactory.getLog(MbeansSource.class);
       Registry registry;
  -    String location;
       String type;
  -    Object source;
   
       // true if we are during the original loading
       boolean loading=true;
  @@ -67,6 +68,14 @@
           this.source=source;
       }
   
  +    public Object getSource() {
  +        return source;
  +    }
  +
  +    public String getLocation() {
  +        return location;
  +    }
  +    
       /** Return the list of mbeans created by this source.
        *  It can be used to implement runtime services.
        *
  @@ -88,11 +97,33 @@
           return mbeans;
       }
       
  +    public void start() throws Exception {
  +        registry.invoke(mbeans, "start", false);        
  +    }
  +
  +    public void stop() throws Exception {
  +        registry.invoke(mbeans, "stop", false);        
  +    }
  +    
  +    public void init() throws Exception {
  +        if( mbeans==null) execute();
  +        if( registry==null ) registry=Registry.getRegistry();
  +        
  +        registry.invoke(mbeans, "init", false);
  +    }
  +    
  +    public void destroy() throws Exception {
  +        registry.invoke(mbeans, "destroy", false);                
  +    }
  +    
  +    public void load() throws Exception {
  +        execute(); // backward compat
  +    }
   
       public void execute() throws Exception {
           if( registry==null ) registry=Registry.getRegistry();
           try {
  -            InputStream stream=(InputStream)source;
  +            InputStream stream=getInputStream();
               long t1=System.currentTimeMillis();
               document = DomUtil.readXml(stream);
   
  @@ -250,7 +281,7 @@
       /** Store the mbeans. 
        * XXX add a background thread to store it periodically 
        */ 
  -    public void store() {
  +    public void save() {
           // XXX customize no often than ( based on standard descriptor ), etc.
           // It doesn't work very well if we call this on each set att - 
           // the triger will work for the first att, but all others will be delayed
  
  
  
  1.5       +25 -1     jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/ModelerSource.java
  
  Index: ModelerSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/ModelerSource.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ModelerSource.java	7 Apr 2003 06:49:33 -0000	1.4
  +++ ModelerSource.java	14 Apr 2003 01:01:55 -0000	1.5
  @@ -2,6 +2,11 @@
   
   import org.apache.commons.modeler.Registry;
   import java.util.List;
  +import java.io.InputStream;
  +import java.io.IOException;
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.net.URL;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   
  @@ -9,6 +14,8 @@
    *
    */
   public class ModelerSource {
  +    protected Object source;
  +    protected String location;
   
       /** Load data, returns a list of items. 
        * 
  @@ -42,5 +49,22 @@
       public void store() {
           // nothing
       }
  -    
  +
  +    protected InputStream getInputStream() throws IOException {
  +        if( source instanceof URL ) {
  +            URL url=(URL)source;
  +            location=url.toString();
  +            return url.openStream();
  +        } else if( source instanceof File ) {
  +            location=((File)source).getAbsolutePath();
  +            return new FileInputStream((File)source);            
  +        } else if( source instanceof String) {
  +            location=(String)source;
  +            return new FileInputStream((String)source);            
  +        } else if( source instanceof InputStream ) {
  +            return (InputStream)source;
  +        } 
  +        return null;
  +    }
  +
   }
  
  
  
  1.1                  jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansSourceMBean.java
  
  Index: MbeansSourceMBean.java
  ===================================================================
  package org.apache.commons.modeler.modules;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  import org.apache.commons.modeler.util.DomUtil;
  import org.apache.commons.modeler.*;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import javax.management.*;
  import javax.management.loading.MLet;
  import javax.xml.transform.TransformerException;
  import java.io.InputStream;
  import java.io.FileOutputStream;
  import java.io.FileNotFoundException;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.HashMap;
  
  
  /**
   * This mbean will load an extended mlet file ( similar in syntax with jboss ).
   * It'll keep track of all attribute changes and update the file when attributes
   * change. 
   */
  public interface MbeansSourceMBean 
  {
      /** Set the source to be used to load the mbeans
       * 
       * @param source File or URL
       */ 
      public void setSource( Object source );
      
      public Object getSource();
      
      /** Return the list of loaded mbeans names
       * 
       * @return List of ObjectName
       */ 
      public List getMBeans();
  
      /** Load the mbeans from the source. Called automatically on init() 
       * 
       * @throws Exception
       */ 
      public void load() throws Exception;
      
      /** Call the init method on all mbeans. Will call load if not done already
       * 
       * @throws Exception
       */ 
      public void init() throws Exception;
  
      /** Save the file.
       */ 
      public void save();
  }
  
  
  

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