User: schaefera
  Date: 02/03/18 14:34:02

  Modified:    src/main/org/jboss/ha/framework/server
                        FarmMemberService.java FarmMemberServiceMBean.java
  Log:
  Fixed the broken Farm Member Service. Now the Main Deployer is emitting JMX
  notification when an object is deployed / undeployed and the Farm Member
  Service is listening for.
  Also the Farm Member Service is self-contained meaning that you only have
  to adjust the farm-service.xml and deployed it (no further adjustments
  necessary even the creation of the farm directory).
  
  Also fixed a problem with URL Deployment Scanner which fails when a new
  directory is added (through addURL()) during startup by another MBean
  because list is changed without recreation of the iterator. Now the
  iterator is replaced by a generated array which does not change when the
  list changes.
  
  Revision  Changes    Path
  1.8       +218 -141  
jbossmx/src/main/org/jboss/ha/framework/server/FarmMemberService.java
  
  Index: FarmMemberService.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/server/FarmMemberService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FarmMemberService.java    22 Feb 2002 04:24:54 -0000      1.7
  +++ FarmMemberService.java    18 Mar 2002 22:34:02 -0000      1.8
  @@ -17,16 +17,27 @@
   import java.net.URL;
   import java.net.MalformedURLException;
   import java.util.Date;
  +import java.util.Hashtable;
   
   import javax.management.ObjectName;
   import javax.management.JMException;
  +import javax.management.MBeanServer;
  +import javax.management.Notification;
  +import javax.management.NotificationFilterSupport;
  +import javax.management.NotificationListener;
   
   import org.jboss.deployment.DeploymentInfo;
   import org.jboss.deployment.DeploymentException;
  +import org.jboss.deployment.MainDeployerMBean;
  +import org.jboss.deployment.DeployerMBean;
   
   import org.jboss.ha.framework.server.FarmMemberServiceMBean.FileContent;
   import org.jboss.ha.framework.interfaces.HAPartition;
   
  +import org.jboss.system.ServiceMBeanSupport;
  +import org.jboss.system.server.ServerConfig;
  +import org.jboss.system.server.ServerConfigLocator;
  +
   /**
    * This class indicates that this JBoss instance is a member of a farm
    * builded by all the classes connecting to each other.
  @@ -43,7 +54,7 @@
    * </ul>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>
  - * @version $Revision: 1.7 $ <p>
  + * @version $Revision: 1.8 $ <p>
    *
    * <b>Revisions:</b> <p>
    *
  @@ -51,27 +62,44 @@
    * <ul>
    *   <li>Initial import
    * </ul>
  + * <p><b>20020316 andreas schaefer:</b>
  + * <ul>
  + *   <li>Adjusted to new Deployer Implementation
  + * </ul>
  + *
  + * @todo AS add the MBean interface generation through XDoclet
  + * @--jmx:mbean extends="org.jboss.system.ServiceMBean"
    **/
  -public class FarmMemberService extends org.jboss.system.ServiceMBeanSupport 
implements FarmMemberServiceMBean, javax.management.MBeanRegistration
  +public class FarmMemberService
  +   extends ServiceMBeanSupport
  +   implements FarmMemberServiceMBean
   {
  -
  +   
  +   // Constants -----------------------------------------------------
  +   
  +   private static final String DEFAULT_DEPLOY_DIRECTORY = "./deploy/farm";
  +   private static final String DEFAULT_SCANNER_NAME = 
"jboss.deployment:type=DeploymentScanner,flavor=URL";
  +   
      // Attributes ----------------------------------------------------
  -
  -
  -   protected ObjectName sFarmMemberService = null;
  -   protected ObjectName sDeployerService = null;
  -   protected ObjectName sClusterPartitionService = null;
  -   protected String backgroundPartition = "DefaultPartition";
  +   
  +   protected ObjectName mFarmMemberName = null;
  +   protected ObjectName mClusterPartitionName = null;
  +   protected String mBackgroundPartition = "DefaultPartition";
      
      protected final static String SERVICE_NAME = "FarmMemberService";
      
      /** A callback to the JMX Agent **/
  -   private javax.management.MBeanServer mServer;
  -
  -   private java.util.Hashtable mDeployedServices = new java.util.Hashtable();
  +   private MBeanServer mServer;
  +   
  +   private Hashtable mDeployedServices = new java.util.Hashtable();
  +   private File mTempDirectory;
  +   private String mFarmDeployDirectory = DEFAULT_DEPLOY_DIRECTORY;
  +   private String mScannerName = DEFAULT_SCANNER_NAME;
  +   private File mDeployDirectory;
  +   private NotificationListener mListener = new Listener();
      
      // Static --------------------------------------------------------
  -
  +   
      // Constructors --------------------------------------------------
      
      /**
  @@ -83,67 +111,18 @@
      }
      
      // Public --------------------------------------------------------
  -   /**
  -    * FIXME FOR COMPILATION ONLY
  -    */
  -   public boolean accepts(DeploymentInfo sdi) { return true;};
  -   
  -   public void init(DeploymentInfo sdi) throws DeploymentException {};
  -   
  -   public void create(DeploymentInfo sdi) throws DeploymentException {};
  -   public void start(DeploymentInfo sdi) throws DeploymentException {};
  -   
  -   public void stop(DeploymentInfo sdi) throws DeploymentException {};
  -   public void destroy(DeploymentInfo sdi) throws DeploymentException {};
  -   /**
  -    * FIXME FOR COMPILATION ONLY
  -    */
  -   
  -   
  -   
  -   
  -   public FilenameFilter getDeployableFilter() {
  -      try {
  -         FilenameFilter lFilter = (FilenameFilter) mServer.getAttribute(
  -            sDeployerService,
  -            "DeployableFilter"
  -         );
  -         log.info( "Deployable Filter is: " + lFilter );
  -         return lFilter;
  -      }
  -      catch( JMException jme ) {
  -         logException( jme );
  -      }
  -      return null;
  -   }
      
  -   public void deploy( String pFileURL )
  -      throws
  -         MalformedURLException, 
  -         IOException, 
  -         DeploymentException
  -   {
  -      deploy( new URL( pFileURL ) );
  -   }
  -
  -   public void undeploy( String pFileURL )
  -      throws
  -         MalformedURLException, 
  -         IOException, 
  -         DeploymentException
  -   {
  -      undeploy( new URL( pFileURL ) );
  -   }
  -
      public boolean isDeployed( String pFileURL )
         throws
            MalformedURLException, 
            DeploymentException
      {
         try {
  -         return ( (Boolean) mServer.getAttribute(
  -            sDeployerService,
  -            "Deployed"
  +         return ( (Boolean) mServer.invoke(
  +            MainDeployerMBean.OBJECT_NAME,
  +            "Deployed",
  +            new Object[] { new URL( pFileURL ) },
  +            new String[] { URL.class.getName() }
            ) ).booleanValue();
         }
         catch( JMException jme ) {
  @@ -151,7 +130,7 @@
            throw new DeploymentException( "Could not retrieve isDeployed attribute 
from local Deployer Service", jme );
         }
      }
  -
  +   
      public void deploy( URL pFile ) {
         try {
            log.info( "deploy(), file: " + pFile );
  @@ -165,7 +144,7 @@
            }
            FileContent lFileContent = getFileContent( lFile );
            HAPartition lHAPartition = (HAPartition) mServer.getAttribute(
  -            sClusterPartitionService,
  +            mClusterPartitionName,
               "HAPartition"
            );
            lHAPartition.callMethodOnCluster(
  @@ -190,7 +169,7 @@
            File lFile = new File( pFile.getFile() );
            Date lFileDate = new Date( lFile.lastModified() );
            HAPartition lHAPartition = (HAPartition) mServer.getAttribute(
  -            sClusterPartitionService,
  +            mClusterPartitionName,
               "HAPartition"
            );
            lHAPartition.callMethodOnCluster(
  @@ -215,31 +194,21 @@
            Date lLastDate = (Date) mDeployedServices.get( pFile.mFile.getName() );
            if( lLastDate == null || lLastDate.before( pDate ) ) {
               // Create File locally and use it
  -            File lFile = new File( "../tmp", pFile.mFile.getName() );
  +            File lFile = new File( mTempDirectory, pFile.mFile.getName() );
               FileOutputStream lOutput = new FileOutputStream( lFile );
               lOutput.write( pFile.mContent );
               lOutput.close();
               log.info( "doDeployment(), deploy locally: " + lFile );
  -            // Deploy file on Service Deployer
  -            mServer.invoke(
  -               sDeployerService,
  -               "deploy",
  -               new Object[] { lFile.toURL().toString() },
  -               new String[] { String.class.getName() }
  -            );
  -            log.info( "doDeployment(), add file served" );
  -            mDeployedServices.put( lFile.getName(), pDate );
  -            // Adjust the date and move the file back to /deploy/farm
  -            // if not already there
  -            File lFarmFile = new File( "../deploy/farm", pFile.mFile.getName() );
  -            if( !lFarmFile.exists() ) {
  -               lFile.setLastModified( pDate.getTime() );
  -               lFile.renameTo( lFarmFile );
  -               log.info( "doDeployment(), file copied back to /deploy/farm" );
  -            } else {
  -               lFile.delete();
  -               log.info( "doDeployment(), file is already in /deploy/farm" );
  +            // Adjust the date and move the file to /deploy/farm
  +            // but delete it first if already there
  +            File lFarmFile = new File( mDeployDirectory, pFile.mFile.getName() );
  +            if( lFarmFile.exists() ) {
  +               lFarmFile.delete();
               }
  +            lFile.setLastModified( pDate.getTime() );
  +            lFile.renameTo( lFarmFile );
  +            log.info( "doDeployment(), file copied back to /deploy/farm" );
  +            mDeployedServices.put( lFile.getName(), pDate );
            }
         }
         catch( Exception e ) {
  @@ -252,26 +221,11 @@
            // First check if file is already deployed
            log.info( "doUndeployment(), File: " + pFile + ", data: " + pDate );
            if( mDeployedServices.containsKey( pFile.getName() ) ) {
  -            // Create File locally and use it
  -            File lFile = new File( "../tmp", pFile.getName() );
  -            log.info( "doUndeployment(), undeploy locally: " + lFile );
  -            // Deploy file on Service Deployer
  -            mServer.invoke(
  -               sDeployerService,
  -               "undeploy",
  -               new Object[] { lFile.toURL().toString() },
  -               new String[] { String.class.getName() }
  -            );
  -            log.info( "doUndeployment(), remove file served" );
  -            mDeployedServices.remove( lFile.getName() );
  -            // Check if the file is still in /deploy/farm and if yes
  -            // then remove it
  -            File lFarmFile = new File( "../deploy/farm", pFile.getName() );
  +            // Remove file if available
  +            File lFarmFile = new File( mDeployDirectory, pFile.getName() );
               if( lFarmFile.exists() ) {
                  lFarmFile.delete();
  -               log.info( "doDeployment(), remove file from /deploy/farm" );
  -            } else {
  -               log.info( "doDeployment(), file is already removed" );
  +               log.info( "doUndeployment(), removed file from /deploy/farm" );
               }
            }
         }
  @@ -301,72 +255,157 @@
         return null;
      }
      
  -   public String getPartitionName ()
  +   public String getPartitionName()
      {
  -      return this.backgroundPartition;
  +      return mBackgroundPartition;
      }
      
  -   public void setPartitionName (String partitionName)
  +   public void setPartitionName( String pPartitionName )
      {
  -      if ((this.getState () != this.STARTED) && (this.getState () != this.STARTING))
  +      if( ( getState () != STARTED ) && ( getState () != STARTING ) )
         {
  -         this.backgroundPartition = partitionName;
  -         
  +         mBackgroundPartition = pPartitionName;
         }
      }
  -
  -
  -
  -
  -
  -
  -
  -
  -
  +   
  +   public String getFarmDeployDirectory() {
  +      return mFarmDeployDirectory;
  +   }
  +   
  +   public void setFarmDeployDirectory( String pDirectory ) {
  +      if( pDirectory == null || pDirectory.trim().equals( "" ) ) {
  +         mFarmDeployDirectory = DEFAULT_DEPLOY_DIRECTORY;
  +      } else {
  +         mFarmDeployDirectory = pDirectory;
  +      }
  +   }
  +   
  +   public String getScannerName() {
  +      return mScannerName;
  +   }
  +   
  +   public void setScannerName( String pName ) {
  +      if( pName == null || pName.trim().equals( "" ) ) {
  +         mScannerName = DEFAULT_SCANNER_NAME;
  +      } else {
  +         mScannerName = pName;
  +      }
  +   }
  +   
      // MBeanRegistration implementation ----------------------------------------
  -
  +   
      /**
  -    * #Description of the Method
  -    *
  -    * @param server Description of Parameter
  -    * @param name Description of Parameter
  -    * @return Description of the Returned Value
  -    * @exception Exception Description of Exception
  +    * Saves the MBeanServer reference, create the Farm Member Name and
  +    * add its Notification Listener to listen for Deployment / Undeployment
  +    * notifications from the {@link org.jboss.system.MainDeployer MainDeployer}.
       */
  -   public ObjectName preRegister (javax.management.MBeanServer pServer, ObjectName 
pName) throws Exception
  +   public ObjectName preRegister( MBeanServer pServer, ObjectName pName )
  +      throws Exception
      {
         mServer = pServer;
  -
         log.info("Farm Member Service MBean online");
  +      mFarmMemberName = new ObjectName( OBJECT_NAME + 
",Partition="+this.mBackgroundPartition );
         
  -      this.sFarmMemberService = new ObjectName( OBJECT_NAME + 
",Partition="+this.backgroundPartition );
  +      // Add itself to the Main-Deployer as new deployer
  +      try {
  +         mServer.addNotificationListener(
  +            MainDeployerMBean.OBJECT_NAME,
  +            mListener,
  +            new Filter(),
  +            null
  +         );
  +      }
  +      catch( Exception e ) {
  +         logException( e );
  +         throw e;
  +      }
         
  -      return this.sFarmMemberService;
  +      return mFarmMemberName;
      }
  -
  +   
  +   /**
  +    * Removes the Notification Listener
  +    **/
  +   public void preDeregister()
  +      throws Exception
  +   {
  +      try {
  +         mServer.removeNotificationListener(
  +            MainDeployerMBean.OBJECT_NAME,
  +            mListener
  +         );
  +      }
  +      catch( Exception e ) {
  +         logException( e );
  +         throw e;
  +      }
  +      super.preDeregister();
  +   }
  +   
      // Service implementation ----------------------------------------
   
      public String getName()
      {
         return "Farm Member Service";
      }
  -
  +   
  +   /**
  +    * Looks up the Server Config instance to figure out the
  +    * temp-directory and the farm-deploy-directory
  +    **/
  +   protected void createService() throws Exception
  +   {
  +      ServerConfig lConfig = ServerConfigLocator.locate();
  +      mTempDirectory = lConfig.getServerTempDir();
  +      mDeployDirectory = new File( lConfig.getServerHomeDir(), mFarmDeployDirectory 
);
  +      if( !mDeployDirectory.exists() ) {
  +         mDeployDirectory.mkdirs();
  +      }
  +   }
  +   
  +   /**
  +    * Register itself as RPC-Handler to the HA-Partition
  +    * and add the farm deployment directory to the scanner
  +    **/
      protected void startService()
         throws Exception
      {
  -      this.sDeployerService = new ObjectName( 
"jboss.system:service=ServiceDeployer" );
  -      this.sClusterPartitionService = new ObjectName( "jboss:service=" + 
this.backgroundPartition );
  -
  +      mClusterPartitionName = new ObjectName( "jboss:service=" + 
mBackgroundPartition );
  +      
         log.debug( "registerRPCHandler" );
         HAPartition lHAPartition = (HAPartition) mServer.getAttribute(
  -         sClusterPartitionService,
  +         mClusterPartitionName,
            "HAPartition"
         );
         lHAPartition.registerRPCHandler( SERVICE_NAME, this );
  +      // Add a new deployment directory for the scanner to scan for
  +      log.debug( "Add a new deployment directory to the scanner: " + 
mDeployDirectory );
  +      mServer.invoke(
  +         new ObjectName( mScannerName ),
  +         "addURL",
  +         new Object[] { mDeployDirectory.toURL() },
  +         new String[] { URL.class.getName() }
  +      );
      }
      
  +   /**
  +    * Remove the farm deployment directory from the scanner
  +    **/
      protected void stopService()
      {
  +      try {
  +         // Add a new deployment directory for the scanner to scan for
  +         log.debug( "Remove the deployment directory from the scanner: " + 
mDeployDirectory );
  +         mServer.invoke(
  +            new ObjectName( mScannerName ),
  +            "removeURL",
  +            new Object[] { mDeployDirectory.toURL() },
  +            new String[] { URL.class.getName() }
  +         );
  +      }
  +      catch( Exception e ) {
  +         log.error( "Could not remove farm-deploy-directory from Scanner", e );
  +      }
      }
   
      // Protected -----------------------------------------------------
  @@ -377,7 +416,7 @@
       *
       * @param e The exception to be logged.
       */
  -   private void logException(Throwable e)
  +   private void logException( Throwable e )
      {
         if (e instanceof javax.management.RuntimeErrorException)
         {
  @@ -403,4 +442,42 @@
         log.error(e);
      }
   
  +   // Private -------------------------------------------------------
  +   
  +   // Inner classes -------------------------------------------------
  +   
  +   /**
  +    * Listener checking if an object was deployed or undeployed and
  +    * then call the appropriate method to perform the deployment /
  +    * undeployment farm-wide.
  +    **/
  +   public class Listener
  +      implements NotificationListener
  +   {
  +      public void handleNotification( Notification pNotification, Object pHandback )
  +      {
  +         URL lURL = (URL) pNotification.getUserData();
  +         if( lURL.toString().indexOf( "deploy/farm" ) >= 0 ) {
  +            if( pNotification.getType().equals( "Deployment" ) ) {
  +               deploy( lURL );
  +            } else
  +            if( pNotification.getType().equals( "Undeployment" ) ) {
  +               undeploy( lURL );
  +            }
  +         }
  +      }
  +   }
  +   
  +   /**
  +    * Filter to reduce the Notifications to of type "Deployment" and
  +    * "undeployment"
  +    **/
  +   public class Filter
  +      extends NotificationFilterSupport
  +   {
  +      public Filter() {
  +         enableType( "Deployment" );
  +         enableType( "Undeployment" );
  +      }
  +   }
   }
  
  
  
  1.7       +39 -5     
jbossmx/src/main/org/jboss/ha/framework/server/FarmMemberServiceMBean.java
  
  Index: FarmMemberServiceMBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/server/FarmMemberServiceMBean.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FarmMemberServiceMBean.java       15 Feb 2002 06:18:27 -0000      1.6
  +++ FarmMemberServiceMBean.java       18 Mar 2002 22:34:02 -0000      1.7
  @@ -9,13 +9,15 @@
   
   import java.io.File;
   import java.io.Serializable;
  +import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.Date;
   
   import javax.management.ObjectName;
   
  -import org.jboss.util.jmx.ObjectNameFactory;
  +import org.jboss.deployment.DeploymentException;
   import org.jboss.system.Service;
  +import org.jboss.util.jmx.ObjectNameFactory;
   
   import org.jboss.ha.framework.server.FarmMemberServiceMBean.FileContent;
   import org.jboss.deployment.DeployerMBean;
  @@ -37,7 +39,7 @@
    * @see Service
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    *
    * <p><b>20011015 andreas schaefer:</b>
    * <ul>
  @@ -45,19 +47,33 @@
    * </ul>
    */
   public interface FarmMemberServiceMBean 
  -   extends DeployerMBean, Service
  +   extends Service
   {
      /** The default object name. */
      ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss:service=FarmMember");
  -
  +   
  +   /**
  +   * Is this file deployed farm-wide
  +   *
  +   * @param pFile URL of the File to be tested
  +   *
  +   * @return True if this file is deployed farm-wide
  +   **/
  +   public boolean isDeployed( String pFileURL )
  +      throws
  +         MalformedURLException, 
  +         DeploymentException;
  +   
      /**
      * Deploys a service on all members of a farm
      *
      * @param pFile File to be deployed
  +   *
  +   * @deprecated Whenever someone is using this method please let
  +   *             me know because this should be private
      **/
      public void deploy( URL pFile );
      
  -   
      /**
      * Name of the Partition used as a cluster definition for the farming
      **/
  @@ -65,12 +81,30 @@
      public void setPartitionName (String partitionName);
      
      /**
  +    * Directory where Objects are copied to to be deploy
  +    * farm-wide. ATTENTION: this must not conflict with
  +    * a default deploy-directory.
  +    **/
  +   public String getFarmDeployDirectory();
  +   public void setFarmDeployDirectory( String pDirectory );
  +   
  +   /**
  +    * Name of the Scanner used to find the objects to be
  +    * deployed
  +    **/
  +   public String getScannerName();
  +   public void setScannerName( String pName );
  +   
  +   /**
      * Checks and if necessary deploys the given file on this
      * member of the farm. If deployed it will also notify
      * all other members to ensure that the file gets deployed.
      *
      * @param pFile Content of the file to be deployed
      * @param pDate Date of the file of the first deployment
  +   *
  +   * @deprecated Whenever someone is using this method please let
  +   *             me know because this should be private
      **/
      public void doDeployment( FileContent pFile, Date pDate );
      
  
  
  

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

Reply via email to