summaryrefslogtreecommitdiff
path: root/gentools/templ.java/MethodRegistryClass.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'gentools/templ.java/MethodRegistryClass.tmpl')
-rw-r--r--gentools/templ.java/MethodRegistryClass.tmpl80
1 files changed, 65 insertions, 15 deletions
diff --git a/gentools/templ.java/MethodRegistryClass.tmpl b/gentools/templ.java/MethodRegistryClass.tmpl
index a243ace00e..c3f11d9f5a 100644
--- a/gentools/templ.java/MethodRegistryClass.tmpl
+++ b/gentools/templ.java/MethodRegistryClass.tmpl
@@ -33,13 +33,19 @@ import java.lang.reflect.Constructor;
import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
-class MainRegistry
+public class MainRegistry
{
private static final HashMap<Long, AMQMethodBodyInstanceFactory> classIDMethodIDVersionBodyMap = new HashMap<Long, AMQMethodBodyInstanceFactory>();
private static final Logger _log = Logger.getLogger(MainRegistry.class);
+
+ private static final int DEFAULT_MINOR_VERSION_COUNT = 10;
+ private static final int DEFAULT_MAJOR_VERSION_COUNT = 10;
+
+ private static VersionSpecificRegistry[][] _specificRegistries = new VersionSpecificRegistry[DEFAULT_MAJOR_VERSION_COUNT][];
+
static
{
%{CLIST} ${reg_map_put_method}
@@ -48,7 +54,9 @@ class MainRegistry
public static AMQMethodBody get(short classID, short methodID, byte major, byte minor, ByteBuffer in, long size)
throws AMQFrameDecodingException
{
- AMQMethodBodyInstanceFactory bodyFactory = classIDMethodIDVersionBodyMap.get(createMapKey(classID,methodID,major,minor));
+ VersionSpecificRegistry registry = getVersionSpecificRegistry(major, minor);
+ AMQMethodBodyInstanceFactory bodyFactory = registry.getMethodBody(classID,methodID);
+
if (bodyFactory == null)
{
throw new AMQFrameDecodingException(_log,
@@ -59,23 +67,65 @@ class MainRegistry
}
+
+ public static VersionSpecificRegistry getVersionSpecificRegistry(byte major, byte minor)
+ {
+ try
+ {
+ return _specificRegistries[(int)major][(int)minor];
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ return null;
+ }
+ catch (NullPointerException e)
+ {
+ return null;
+ }
+
+
+ }
+ private static VersionSpecificRegistry addVersionSpecificRegistry(byte major, byte minor)
+ {
+ VersionSpecificRegistry[][] registries = _specificRegistries;
+ if(major >= registries.length)
+ {
+ _specificRegistries = new VersionSpecificRegistry[(int)major + 1][];
+ System.arraycopy(registries, 0, _specificRegistries, 0, registries.length);
+ registries = _specificRegistries;
+ }
+ if(registries[major] == null)
+ {
+ registries[major] = new VersionSpecificRegistry[ minor >= DEFAULT_MINOR_VERSION_COUNT ? minor + 1 : DEFAULT_MINOR_VERSION_COUNT ];
+ }
+ else if(registries[major].length <= minor)
+ {
+ VersionSpecificRegistry[] minorArray = registries[major];
+ registries[major] = new VersionSpecificRegistry[ minor + 1 ];
+ System.arraycopy(minorArray, 0, registries[major], 0, minorArray.length);
+
+ }
+
+ VersionSpecificRegistry newRegistry = new VersionSpecificRegistry(major,minor);
+
+ registries[major][minor] = newRegistry;
+
+ return newRegistry;
+ }
+
private static void registerMethod(short classID, short methodID, byte major, byte minor, AMQMethodBodyInstanceFactory instanceFactory )
{
- classIDMethodIDVersionBodyMap.put(createMapKey(classID,methodID,major,minor), instanceFactory);
+ VersionSpecificRegistry registry = getVersionSpecificRegistry(major,minor);
+ if(registry == null)
+ {
+ registry = addVersionSpecificRegistry(major,minor);
+
+ }
+
+ registry.registerMethod(classID, methodID, instanceFactory);
+
}
- private static Long createMapKey(short classID, short methodID, byte major, byte minor)
- {
- /**
- * Mapping of 4 components into a guaranteed unique key:
- * MSB LSB
- * +----+----+----+----+----+----+-----+-----+
- * | 0 | classID |methodID |major|minor|
- * +----+----+----+----+----+----+-----+-----+
- */
- return new Long(((long)classID << 32) + ((long)methodID << 16) + ((long)major << 8) + minor);
- }
-
}