User: schaefera Date: 01/11/11 20:24:18 Added: src/main/org/jboss/ha/framework/server FarmMemberService.java FarmMemberServiceMBean.java Log: Reworked Farm which is now part of clustering and uses JavaGroups. Right now only the "farm-service.xml" must be deployed on each node of the farm and then servies must be placed into "/jboss/deploy/farm" and voila you this servies deployed on all nodes of the farm. Updated the JSR-77 file and created the MEJB Session Bean which allows the client to retrieve management info from the server and then manage the server. The Session Bean is a vain implementation. Revision Changes Path 1.1 jbossmx/src/main/org/jboss/ha/framework/server/FarmMemberService.java Index: FarmMemberService.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha.framework.server; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FilenameFilter; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Date; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.StringTokenizer; import javax.management.InstanceNotFoundException; import javax.management.JMException; import javax.management.JMRuntimeException; import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanRegistration; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.ReflectionException; import javax.management.RuntimeErrorException; import javax.management.RuntimeMBeanException; import javax.management.RuntimeOperationsException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.deployment.DeploymentException; import org.jboss.ha.framework.interfaces.HAPartition; import org.jboss.system.ServiceMBeanSupport; /** * This class indicates that this JBoss instance is a member of a farm * builded by all the classes connecting to each other. * <br> * How to set up a farm: * <ul> * <li>Start a Farm Member Service MBean on each node becoming a member * of the farm * <li>Add each node to an existing member of the farm. When there is * no node added then first node which adds another node becomes * the initial member of the farm. To do so use {@link #addMember * addMember()} method or add the new members in bulk with * {@link #setMembers setMembers()} method. * </ul> * * @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a> * @version $Revision: 1.1 $ <p> * * <b>Revisions:</b> <p> * * <p><b>20011015 andreas schaefer:</b> * <ul> * <li>Initial import * </ul> **/ public class FarmMemberService extends ServiceMBeanSupport implements FarmMemberServiceMBean, MBeanRegistration { // Attributes ---------------------------------------------------- private static ObjectName sFarmMemberService = null; private static ObjectName sDeployerService = null; private static ObjectName sClusterPartitionService = null; protected final static String SERVICE_NAME = "FarmMemberService"; /** A callback to the JMX Agent **/ private MBeanServer mServer; private Hashtable mDeployedServices = new Hashtable(); // Static -------------------------------------------------------- // Constructors -------------------------------------------------- /** * Creates a undefined farm member service. Both the local JNDI-Server Name * as well as the local Adaptor JNDI-Name must be set before starting this * MBean. **/ public FarmMemberService() { } // Public -------------------------------------------------------- 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" ) ).booleanValue(); } catch( JMException jme ) { logException( jme ); throw new DeploymentException( "Could not retrieve isDeployed attribute from local Deployer Service", jme ); } } public void deploy( URL pFile ) { try { log.info( "deploy(), file: " + pFile ); // Get the date of the file File lFile = new File( pFile.getFile() ); Date lFileDate = new Date( lFile.lastModified() ); FileContent lFileContent = getFileContent( lFile ); HAPartition lHAPartition = (HAPartition) mServer.getAttribute( sClusterPartitionService, "HAPartition" ); lHAPartition.callMethodOnCluster( SERVICE_NAME, "doDeployment", new Object[] { lFileContent, lFileDate }, false ); } catch( Exception e ) { logException( e ); } } public void doDeployment( FileContent pFile, Date pDate ) { try { // First check if file not already deployed log.info( "doDeployment(), File: " + pFile + ", data: " + pDate ); 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() ); 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 ); } } catch( Exception e ) { logException( e ); } } public FileContent getFileContent( File pFile ) { try { // Create File ByteArray byte[] lBuffer = new byte[ 1024 ]; InputStream lInput = new FileInputStream( pFile ); ByteArrayOutputStream lOutput = new ByteArrayOutputStream(); int j = 0; while( ( j = lInput.read( lBuffer ) ) > 0 ) { lOutput.write( lBuffer, 0, j ); } return new FileContent( pFile, lOutput.toByteArray() ); } catch( FileNotFoundException fnfe ) { logException( fnfe ); } catch( IOException ioe ) { logException( ioe ); } return null; } // 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 */ public ObjectName preRegister( MBeanServer pServer, ObjectName pName ) throws Exception { mServer = pServer; log.info("Farm Member Service MBean online"); return new ObjectName( OBJECT_NAME ); } // Service implementation ---------------------------------------- public String getName() { return "Farm Member Service"; } protected void startService() throws Exception { log.debug( "registerRPCHandler" ); HAPartition lHAPartition = (HAPartition) mServer.getAttribute( sClusterPartitionService, "HAPartition" ); lHAPartition.registerRPCHandler( SERVICE_NAME, this ); } protected void stopService() { } // Protected ----------------------------------------------------- /** * Go through the myriad of nested JMX exception to pull out the true * exception if possible and log it. * * @param e The exception to be logged. */ private void logException(Throwable e) { if (e instanceof RuntimeErrorException) { e = ((RuntimeErrorException)e).getTargetError(); } else if (e instanceof RuntimeMBeanException) { e = ((RuntimeMBeanException)e).getTargetException(); } else if (e instanceof RuntimeOperationsException) { e = ((RuntimeOperationsException)e).getTargetException(); } else if (e instanceof MBeanException) { e = ((MBeanException)e).getTargetException(); } else if (e instanceof ReflectionException) { e = ((ReflectionException)e).getTargetException(); } e.printStackTrace(); log.error(e); } static { try { sFarmMemberService = new ObjectName( OBJECT_NAME ); sDeployerService = new ObjectName( "JBOSS-SYSTEM:service=ServiceDeployer" ); sClusterPartitionService = new ObjectName( "JBOSS-SYSTEM:service=DefaultPartition" ); } catch( JMException jme ) { } } } 1.1 jbossmx/src/main/org/jboss/ha/framework/server/FarmMemberServiceMBean.java Index: FarmMemberServiceMBean.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha.framework.server; import java.io.File; import java.io.Serializable; import java.net.URL; import java.util.Date; import java.util.Hashtable; import java.util.List; import javax.management.ObjectName; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.deployment.DeployerMBean; import org.jboss.system.Service; /** * This is the main Service Controller API. * * <p>A controller can deploy a service to a JBOSS-SYSTEM * It installs by delegating, it configures by delegating * <b>Attention:</b><br> * JNDI-Server Name must be the same used on ALL members of * the farm. Therefore when you use "www.gugus.com" on one * member then you can't use "gugus.com" on another member * because the Name is used to compare the members. Also * local names must be full qualified if a member of the farm * is outsite therefore "box1.gugus.com" must be used everywhere * and cannot be shortent to "box1" on some of the members. * * @see Service * * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a> * @version $Revision: 1.1 $ * * <p><b>20011015 andreas schaefer:</b> * <ul> * <li>Initial import * </ul> */ public interface FarmMemberServiceMBean extends Service, DeployerMBean { /** The default object name. */ String OBJECT_NAME = "JBOSS-SYSTEM:spine=FarmMember"; /** * Deploys a service on all members of a farm * * @param pFile File to be deployed **/ public void deploy( URL pFile ); /** * 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 **/ public void doDeployment( FileContent pFile, Date pDate ); public class FileContent implements Serializable { public File mFile; public byte[] mContent; public FileContent( File pFile, byte[] pContent ) { mFile = pFile; mContent = pContent; } } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development