[jboss-cvs] JBoss Messaging SVN: r1405 - trunk/docs/examples/common/src/org/jboss/example/jms/common

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 29 20:33:15 EDT 2006


Author: clebert.suconic at jboss.com
Date: 2006-09-29 20:33:13 -0400 (Fri, 29 Sep 2006)
New Revision: 1405

Added:
   trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupportCluster.java
Modified:
   trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
   trunk/docs/examples/common/src/org/jboss/example/jms/common/Util.java
Log:
Adding proposed clustered example

Modified: trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java	2006-09-30 00:32:08 UTC (rev 1404)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java	2006-09-30 00:33:13 UTC (rev 1405)
@@ -7,6 +7,7 @@
 package org.jboss.example.jms.common;
 
 import javax.jms.ConnectionMetaData;
+import javax.naming.InitialContext;
 
 /**
  * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
@@ -39,7 +40,7 @@
    // Public --------------------------------------------------------
 
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
 
    protected abstract void example() throws Exception;
@@ -126,8 +127,13 @@
 
    // Private -------------------------------------------------------
 
-   private void setup() throws Exception
+   protected void setup() throws Exception
    {
+       setup(null);
+   }
+
+   protected void setup(InitialContext ic) throws Exception
+   {
       String destinationName;
 
       if (isQueueExample())
@@ -143,23 +149,28 @@
             "/topic/"  + (destinationName == null ? DEFAULT_TOPIC_NAME : destinationName);
       }
 
-      if (!Util.doesDestinationExist(jndiDestinationName))
+      if (!Util.doesDestinationExist(jndiDestinationName,ic))
       {
          System.out.println("Destination " + jndiDestinationName + " does not exist, deploying it");
-         Util.deployQueue(jndiDestinationName);
+         Util.deployQueue(jndiDestinationName,ic);
          deployed = true;
       }
    }
 
-   private void tearDown() throws Exception
+   protected void tearDown() throws Exception
    {
+       tearDown(null);
+   }
+
+   protected void tearDown(InitialContext ic) throws Exception
+   {
       if (deployed)
       {
-         Util.undeployQueue(jndiDestinationName);
+         Util.undeployQueue(jndiDestinationName,ic);
       }
    }
 
-   private void reportResultAndExit()
+   protected void reportResultAndExit()
    {
       if (isFailure())
       {

Added: trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupportCluster.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupportCluster.java	2006-09-30 00:32:08 UTC (rev 1404)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupportCluster.java	2006-09-30 00:33:13 UTC (rev 1405)
@@ -0,0 +1,65 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.common;
+
+import javax.naming.InitialContext;
+import javax.naming.Context;
+import java.util.Properties;
+
+/**
+ * @author Clebert Suconic
+ */
+public abstract class ExampleSupportCluster extends ExampleSupport {
+
+    /** This will get the Context specific to a cluster */
+    public InitialContext getServerContext(int serverNumber) throws Exception
+    {
+        String serverIP = System.getProperty("CLUSTER_IP_" + serverNumber);
+        if (serverIP==null)
+        {
+            String errorMessage = "You should define CLUSTER_IP_" + serverNumber + " in your java properties or in your server.properites at your example's directory";
+            System.out.println(errorMessage);
+            throw new Exception(errorMessage);
+        }
+        return getServerContext(serverIP);
+    }
+
+    public InitialContext getServerContext(String serverIP) throws Exception
+    {
+        String jndiProviderClass = "org.jnp.interfaces.NamingContextFactory";
+        Properties contextProperties = new Properties();
+        contextProperties.put(Context.INITIAL_CONTEXT_FACTORY,
+            jndiProviderClass);
+        contextProperties.put(Context.PROVIDER_URL,
+            "jnp://" + serverIP+ ":1099");
+        return new InitialContext(contextProperties);
+    }
+
+
+
+    protected void run()
+    {
+       try
+       {
+          InitialContext ct1 = getServerContext(1);
+          InitialContext ct2 = getServerContext(2);
+           setup(ct1);
+           setup(ct2);
+          example();
+           tearDown(ct1);
+           tearDown(ct2);
+       }
+       catch(Throwable t)
+       {
+          t.printStackTrace();
+          setFailure(true);
+       }
+
+       reportResultAndExit();
+    }
+
+}

Modified: trunk/docs/examples/common/src/org/jboss/example/jms/common/Util.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/Util.java	2006-09-30 00:32:08 UTC (rev 1404)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/Util.java	2006-09-30 00:33:13 UTC (rev 1405)
@@ -38,9 +38,16 @@
 
    // Static --------------------------------------------------------
 
+
    public static boolean doesDestinationExist(String jndiName) throws Exception
    {
-      InitialContext ic = new InitialContext();
+       return doesDestinationExist(jndiName, null);
+   }
+
+   public static boolean doesDestinationExist(String jndiName, InitialContext ic) throws Exception
+   {
+      if (ic==null)
+          ic = new InitialContext();
       try
       {
          ic.lookup(jndiName);
@@ -54,8 +61,13 @@
 
    public static void deployQueue(String jndiName) throws Exception
    {
-      MBeanServerConnection mBeanServer = lookupMBeanServerProxy();
+       deployQueue(jndiName,null);
+   }
 
+   public static void deployQueue(String jndiName, InitialContext ic) throws Exception
+   {
+      MBeanServerConnection mBeanServer = lookupMBeanServerProxy(ic);
+
       ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
 
       String queueName = jndiName.substring(jndiName.lastIndexOf('/') + 1);
@@ -69,8 +81,13 @@
 
    public static void undeployQueue(String jndiName) throws Exception
    {
-      MBeanServerConnection mBeanServer = lookupMBeanServerProxy();
+       undeployQueue(jndiName,null);
+   }
 
+   public static void undeployQueue(String jndiName, InitialContext ic) throws Exception
+   {
+      MBeanServerConnection mBeanServer = lookupMBeanServerProxy(ic);
+
       ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
 
       String queueName = jndiName.substring(jndiName.lastIndexOf('/') + 1);
@@ -82,11 +99,14 @@
       System.out.println("Queue " + jndiName + " undeployed");
    }
 
-   public static MBeanServerConnection lookupMBeanServerProxy() throws Exception
+   public static MBeanServerConnection lookupMBeanServerProxy(InitialContext ic) throws Exception
    {
-      InitialContext ic = new InitialContext();
+      if (ic==null)
+      {
+        ic = new InitialContext();
+      }
       MBeanServerConnection p = (MBeanServerConnection)ic.lookup("jmx/invoker/RMIAdaptor");
-      ic.close();
+      //ic.close();
       return p;
    }
 




More information about the jboss-cvs-commits mailing list