dev@shoal.java.net

Code review

From: Sheetal Vartak <Sheetal.Vartak_at_Sun.COM>
Date: Mon, 11 Feb 2008 16:46:59 -0800

Hi,
Shreedhar and I had discussed about having a way to plug in any service
provider into Shoal and removing the hard dependency on JXTA imports in
the GMSContextFactory class. Due to some logging related issues, the
JXTA provider class was being initialized by calling

new com.sun.enterprise.ee.cms.impl.jxta.GMSContext(...).

I have tried to replace this by a more generic way by introducing a
properties file called "shoal.properties" (just like there is a
jndi.properties file in naming).
The shoal.properties file holds the value of the group communication
provider class which is being plugged into Shoal.

Attached are the diffs as well as the sources.

Shreedhar : Changes to NetworkManager and JxtaUtil will not be checked
in. They have been included here only to show that the JXTA logging
messages can be seen by turning on the logging in NetworkManager for
JXTA and the filter for one of the JXTA classes. The rungmsdemo.sh shows
all the JXTA output (set to FINEST).

Thanks
Sheetal

-- 


? build
? dist
? .shoal
? Gms.iml
? diff
? shoal.properties
? src/Src.iml
Index: src/java/com/sun/enterprise/ee/cms/core/GMSConstants.java
===================================================================
RCS file: /cvs/shoal/gms/src/java/com/sun/enterprise/ee/cms/core/GMSConstants.java,v
retrieving revision 1.2
diff -u -r1.2 GMSConstants.java
--- src/java/com/sun/enterprise/ee/cms/core/GMSConstants.java 12 Jun 2007 18:39:38 -0000 1.2
+++ src/java/com/sun/enterprise/ee/cms/core/GMSConstants.java 12 Feb 2008 00:29:33 -0000
@@ -45,10 +45,12 @@
  */
 public class GMSConstants {
 
- public static final String DEFAULT_GROUP_COMMUNICATION_PROVIDER="Jxta";
- public static final String GROUP_COMMUNICATION_PROVIDER =
- System.getProperty ("SHOAL_GROUP_COMMUNICATION_PROVIDER",
- DEFAULT_GROUP_COMMUNICATION_PROVIDER);
+ //public static final String DEFAULT_GROUP_COMMUNICATION_PROVIDER="Jxta";
+ //public static final String GROUP_COMMUNICATION_PROVIDER =
+ // System.getProperty ("SHOAL_GROUP_COMMUNICATION_PROVIDER",
+ // DEFAULT_GROUP_COMMUNICATION_PROVIDER);
+ public static final String SHOAL_GROUP_COMMUNICATION_PROVIDER = "shoal.group.provider.class.name";
+ public static final String SHOAL_PROPERTIES_FILE = "shoal.properties";
     public static enum shutdownType { INSTANCE_SHUTDOWN, GROUP_SHUTDOWN }
     public static enum shutdownState { INITIATED, COMPLETED }
 }
Index: src/java/com/sun/enterprise/ee/cms/impl/common/GMSContextFactory.java
===================================================================
RCS file: /cvs/shoal/gms/src/java/com/sun/enterprise/ee/cms/impl/common/GMSContextFactory.java,v
retrieving revision 1.2
diff -u -r1.2 GMSContextFactory.java
--- src/java/com/sun/enterprise/ee/cms/impl/common/GMSContextFactory.java 12 Jun 2007 18:41:16 -0000 1.2
+++ src/java/com/sun/enterprise/ee/cms/impl/common/GMSContextFactory.java 12 Feb 2008 00:29:33 -0000
@@ -42,6 +42,10 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.io.FileInputStream;
+import java.io.IOException;
 
 /**
  * Produces and retains the GMSContext for the lifetime of the GMS instance
@@ -55,22 +59,33 @@
 
     private GMSContextFactory () { }
 
- //TODO: Shreedhar's comment: The invocation of appropriate provider's context has got to get better
     static GMSContext produceGMSContext(final String serverToken,
                             final String groupName,
                             final GroupManagementService.MemberType memberType,
                             final Properties properties){
         GMSContext ctx;
- final String gmsContextProvider = GMSConstants.GROUP_COMMUNICATION_PROVIDER;
- if((ctx = ctxCache.get( groupName )) == null){
- if(gmsContextProvider.equals(
- GMSConstants.DEFAULT_GROUP_COMMUNICATION_PROVIDER))
- {
- ctx = new com.sun.enterprise.ee.cms.impl.jxta.GMSContext(
- serverToken, groupName, memberType, properties);
+ if ((ctx = ctxCache.get(groupName)) == null) {
+ try {
+ Class className = Class.forName(getClassToLoad());
+ Constructor constructor = className.getConstructor(new Class[]{String.class,
+ String.class,
+ GroupManagementService.MemberType.class,
+ Properties.class});
+ ctx = (GMSContext) constructor.newInstance(
+ new Object[]{serverToken, groupName, memberType, properties});
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Error in instantiating the group provider :", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Error in instantiating the group provider :", e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Error in instantiating the group provider :", e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException("Error in instantiating the group provider :", e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Error in instantiating the group provider :", e);
             }
- ctxCache.put(groupName, ctx);
         }
+ ctxCache.put(groupName, ctx);
         return ctx;
     }
  
@@ -81,4 +96,16 @@
     public static void removeGMSContext ( final String groupName ) {
         ctxCache.remove( groupName );
     }
+
+ private static String getClassToLoad() throws RuntimeException {
+ Properties props = new Properties();
+ String className;
+ try {
+ props.load(new FileInputStream(GMSConstants.SHOAL_PROPERTIES_FILE));
+ className = props.getProperty(GMSConstants.SHOAL_GROUP_COMMUNICATION_PROVIDER);
+ return className;
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot find the Service Provider's class to instantiate...");
+ }
+ }
 }
Index: src/java/com/sun/enterprise/jxtamgmt/JxtaUtil.java
===================================================================
RCS file: /cvs/shoal/gms/src/java/com/sun/enterprise/jxtamgmt/JxtaUtil.java,v
retrieving revision 1.5
diff -u -r1.5 JxtaUtil.java
--- src/java/com/sun/enterprise/jxtamgmt/JxtaUtil.java 19 Oct 2007 03:47:45 -0000 1.5
+++ src/java/com/sun/enterprise/jxtamgmt/JxtaUtil.java 12 Feb 2008 00:29:33 -0000
@@ -114,13 +114,13 @@
         try {
             consoleHandler.setLevel(Level.ALL);
             consoleHandler.setFormatter(new NiceLogFormatter());
- //SelectiveLogFilter filter = new SelectiveLogFilter();
+ SelectiveLogFilter filter = new SelectiveLogFilter();
             //filter.add(HealthMonitor.class.getName());
             //filter.add(MasterNode.class.getName());
             //filter.add(ClusterView.class.getName());
             //filter.add(NetworkManager.class.getName());
- //filter.add(net.jxta.impl.rendezvous.RendezVousServiceImpl.class.getName());
- //consoleHandler.setFilter(filter);
+ filter.add(net.jxta.impl.rendezvous.RendezVousServiceImpl.class.getName());
+ consoleHandler.setFilter(filter);
         } catch (SecurityException e) {
             new ErrorManager().error(
                     "Exception caught in setting up ConsoleHandler ",
Index: src/java/com/sun/enterprise/jxtamgmt/NetworkManager.java
===================================================================
RCS file: /cvs/shoal/gms/src/java/com/sun/enterprise/jxtamgmt/NetworkManager.java,v
retrieving revision 1.40
diff -u -r1.40 NetworkManager.java
--- src/java/com/sun/enterprise/jxtamgmt/NetworkManager.java 8 Feb 2008 22:19:46 -0000 1.40
+++ src/java/com/sun/enterprise/jxtamgmt/NetworkManager.java 12 Feb 2008 00:29:33 -0000
@@ -145,7 +145,7 @@
     NetworkManager(final String groupName,
                    final String instanceName,
                    final Map properties) {
- System.setProperty(Logging.JXTA_LOGGING_PROPERTY, Level.OFF.toString());
+ System.setProperty(Logging.JXTA_LOGGING_PROPERTY, Level.FINEST.toString());
         this.groupName = groupName;
         this.instanceName = instanceName;