[hornetq-commits] JBoss hornetq SVN: r10071 - in trunk: src/main/org/hornetq/core/protocol/core/impl and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Dec 22 21:11:49 EST 2010


Author: igarashitm
Date: 2010-12-22 21:11:49 -0500 (Wed, 22 Dec 2010)
New Revision: 10071

Modified:
   trunk/src/config/common/hornetq-version.properties
   trunk/src/main/org/hornetq/core/protocol/core/impl/HornetQPacketHandler.java
   trunk/src/main/org/hornetq/core/version/Version.java
   trunk/src/main/org/hornetq/core/version/impl/VersionImpl.java
   trunk/src/main/org/hornetq/utils/VersionLoader.java
   trunk/tests/src/org/hornetq/tests/unit/core/version/impl/VersionImplTest.java
Log:
https://issues.jboss.org/browse/HORNETQ-445
added version compatibility matrix validation



Modified: trunk/src/config/common/hornetq-version.properties
===================================================================
--- trunk/src/config/common/hornetq-version.properties	2010-12-22 23:11:40 UTC (rev 10070)
+++ trunk/src/config/common/hornetq-version.properties	2010-12-23 02:11:49 UTC (rev 10071)
@@ -6,3 +6,4 @@
 hornetq.version.versionSuffix=CR1
 hornetq.version.versionTag=CR1
 hornetq.netty.version=@NETTY.VERSION@
+hornetq.version.compatibleVersionList=100-1000

Modified: trunk/src/main/org/hornetq/core/protocol/core/impl/HornetQPacketHandler.java
===================================================================
--- trunk/src/main/org/hornetq/core/protocol/core/impl/HornetQPacketHandler.java	2010-12-22 23:11:40 UTC (rev 10070)
+++ trunk/src/main/org/hornetq/core/protocol/core/impl/HornetQPacketHandler.java	2010-12-23 02:11:49 UTC (rev 10071)
@@ -127,8 +127,18 @@
       try
       {
          Version version = server.getVersion();
+         int[] compatibleList = version.getCompatibleVersionList();
+         boolean isCompatibleClient = false;
+         for(int i=0; i<compatibleList.length; i++)
+         {
+            if(compatibleList[i] == request.getVersion())
+            {
+               isCompatibleClient = true;
+               break;
+            }
+         }
 
-         if (version.getIncrementingVersion() != request.getVersion())
+         if (!isCompatibleClient)
          {
             log.warn("Client with version " + request.getVersion() +
                      " and address " +

Modified: trunk/src/main/org/hornetq/core/version/Version.java
===================================================================
--- trunk/src/main/org/hornetq/core/version/Version.java	2010-12-22 23:11:40 UTC (rev 10070)
+++ trunk/src/main/org/hornetq/core/version/Version.java	2010-12-23 02:11:49 UTC (rev 10071)
@@ -35,6 +35,8 @@
    String getVersionSuffix();
 
    int getIncrementingVersion();
+   
+   int[] getCompatibleVersionList();
 
    String getNettyVersion();
 }

Modified: trunk/src/main/org/hornetq/core/version/impl/VersionImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/version/impl/VersionImpl.java	2010-12-22 23:11:40 UTC (rev 10070)
+++ trunk/src/main/org/hornetq/core/version/impl/VersionImpl.java	2010-12-23 02:11:49 UTC (rev 10071)
@@ -46,9 +46,11 @@
    private final int incrementingVersion;
 
    private final String versionSuffix;
-
+   
    private final String nettyVersion;
 
+   private final int[] compatibleVersionList;
+
    // Constructors --------------------------------------------------
 
    public VersionImpl(final String versionName,
@@ -57,7 +59,8 @@
                       final int microVersion,
                       final int incrementingVersion,
                       final String versionSuffix,
-                      final String nettyVersion)
+                      final String nettyVersion,
+                      final int[] compatibleVersionList)
    {
       this.versionName = versionName;
 
@@ -72,6 +75,8 @@
       this.versionSuffix = versionSuffix;
 
       this.nettyVersion = nettyVersion;
+      
+      this.compatibleVersionList = compatibleVersionList;
    }
 
    // Version implementation ------------------------------------------
@@ -126,6 +131,11 @@
       return nettyVersion;
    }
 
+   public int[] getCompatibleVersionList()
+   {
+      return compatibleVersionList;
+   }
+
    // Public -------------------------------------------------------
 
    @Override

Modified: trunk/src/main/org/hornetq/utils/VersionLoader.java
===================================================================
--- trunk/src/main/org/hornetq/utils/VersionLoader.java	2010-12-22 23:11:40 UTC (rev 10070)
+++ trunk/src/main/org/hornetq/utils/VersionLoader.java	2010-12-23 02:11:49 UTC (rev 10071)
@@ -16,6 +16,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
+import java.util.StringTokenizer;
 
 import org.hornetq.core.logging.Logger;
 import org.hornetq.core.version.Version;
@@ -81,13 +82,16 @@
             int incrementingVersion = Integer.valueOf(versionProps.getProperty("hornetq.version.incrementingVersion"));
             String versionSuffix = versionProps.getProperty("hornetq.version.versionSuffix");
             String nettyVersion = versionProps.getProperty("hornetq.netty.version");
+            int[] compatibleVersionArray = parseCompatibleVersionList(versionProps.getProperty("hornetq.version.compatibleVersionList"));
+            
             return new VersionImpl(versionName,
                                    majorVersion,
                                    minorVersion,
                                    microVersion,
                                    incrementingVersion,
                                    versionSuffix,
-                                   nettyVersion);
+                                   nettyVersion,
+                                   compatibleVersionArray);
          }
          catch (IOException e)
          {
@@ -108,4 +112,68 @@
       }
 
    }
+
+   private static int[] parseCompatibleVersionList(String property) throws IOException
+   {
+      int[] verArray = new int[0];
+      StringTokenizer tokenizer = new StringTokenizer(property,",");
+      while(tokenizer.hasMoreTokens())
+      {
+         int from = -1, to = -1;
+         String token = tokenizer.nextToken();
+         
+         int cursor = 0;
+         char firstChar = token.charAt(0);
+         if(firstChar == '-')
+         {
+            // "-n" pattern
+            from = 0;
+            cursor++;
+            for(;cursor < token.length() && Character.isDigit(token.charAt(cursor)); cursor++);
+            if(cursor > 1)
+            {
+               to = Integer.parseInt(token.substring(1, cursor));
+            }
+         }
+         else if(Character.isDigit(firstChar))
+         {
+            for(;cursor < token.length() && Character.isDigit(token.charAt(cursor)); cursor++);
+            from = Integer.parseInt(token.substring(0, cursor));
+            
+            if(cursor == token.length())
+            {
+               // just "n" pattern
+               to = from;
+            }
+            else if(token.charAt(cursor)== '-')
+            {
+               cursor++;
+               if(cursor == token.length())
+               {
+                  // "n-" pattern
+                  to = Integer.MAX_VALUE;
+               }
+               else
+               {
+                  // "n-n" pattern
+                  to = Integer.parseInt(token.substring(cursor));
+               }
+            }
+         }
+
+         if(from != -1 && to != -1)
+         {
+            // merge version array
+            int[] newArray = new int[verArray.length + to-from+1];
+            System.arraycopy(verArray, 0, newArray, 0, verArray.length);
+            for(int i=0; i<to-from+1; i++)
+            {
+               newArray[verArray.length+i] = from + i;
+            }
+            verArray = newArray;
+         }
+      }
+      
+      return verArray;
+   }
 }

Modified: trunk/tests/src/org/hornetq/tests/unit/core/version/impl/VersionImplTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/version/impl/VersionImplTest.java	2010-12-22 23:11:40 UTC (rev 10070)
+++ trunk/tests/src/org/hornetq/tests/unit/core/version/impl/VersionImplTest.java	2010-12-23 02:11:49 UTC (rev 10071)
@@ -51,13 +51,15 @@
       int incrementingVersion = 10;
       String versionSuffix = "suffix";
       String nettyVersion = "netty";
+      int[] compatibleVersionList = {7,8,9,10};
       VersionImpl version = new VersionImpl(versionName,
                                             majorVersion,
                                             minorVersion,
                                             microVersion,
                                             incrementingVersion,
                                             versionSuffix,
-                                            nettyVersion);
+                                            nettyVersion,
+                                            compatibleVersionList);
 
       Assert.assertEquals(versionName, version.getVersionName());
       Assert.assertEquals(majorVersion, version.getMajorVersion());
@@ -70,9 +72,9 @@
    public void testEquals() throws Exception
    {
       String nettyVersion = "netty";
-      VersionImpl version = new VersionImpl("HORNETQ", 2, 0, 1, 10, "suffix", nettyVersion);
-      VersionImpl sameVersion = new VersionImpl("HORNETQ", 2, 0, 1, 10, "suffix", nettyVersion);
-      VersionImpl differentVersion = new VersionImpl("HORNETQ", 2, 0, 1, 11, "suffix", nettyVersion);
+      VersionImpl version = new VersionImpl("HORNETQ", 2, 0, 1, 10, "suffix", nettyVersion, new int[]{7,8,9,10});
+      VersionImpl sameVersion = new VersionImpl("HORNETQ", 2, 0, 1, 10, "suffix", nettyVersion, new int[]{7,8,9,10});
+      VersionImpl differentVersion = new VersionImpl("HORNETQ", 2, 0, 1, 11, "suffix", nettyVersion, new int[]{7,8,9,10,11});
 
       Assert.assertFalse(version.equals(new Object()));
 
@@ -84,7 +86,7 @@
    public void testSerialize() throws Exception
    {
       String nettyVersion = "netty";
-      VersionImpl version = new VersionImpl("uyiuy", 3, 7, 6, 12, "uhuhuh", nettyVersion);
+      VersionImpl version = new VersionImpl("uyiuy", 3, 7, 6, 12, "uhuhuh", nettyVersion, new int[]{9,10,11,12});
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(baos);
       oos.writeObject(version);



More information about the hornetq-commits mailing list