summaryrefslogtreecommitdiff
path: root/gentools/templ.java
diff options
context:
space:
mode:
Diffstat (limited to 'gentools/templ.java')
-rw-r--r--gentools/templ.java/MethodBodyClass.tmpl33
-rw-r--r--gentools/templ.java/MethodRegistryClass.tmpl80
2 files changed, 94 insertions, 19 deletions
diff --git a/gentools/templ.java/MethodBodyClass.tmpl b/gentools/templ.java/MethodBodyClass.tmpl
index 249738e109..99663ed815 100644
--- a/gentools/templ.java/MethodBodyClass.tmpl
+++ b/gentools/templ.java/MethodBodyClass.tmpl
@@ -42,6 +42,12 @@ public class ${CLASS}${METHOD}Body extends AMQMethodBody implements EncodableAMQ
{
return new ${CLASS}${METHOD}Body(major, minor, in);
}
+
+ public AMQMethodBody newInstance(byte major, byte minor, int clazzID, int methodID, ByteBuffer in, long size) throws AMQFrameDecodingException
+ {
+ return new ${CLASS}${METHOD}Body(major, minor, clazzID, methodID, in);
+ }
+
};
public static AMQMethodBodyInstanceFactory getFactory()
@@ -82,12 +88,18 @@ public class ${CLASS}${METHOD}Body extends AMQMethodBody implements EncodableAMQ
public ${CLASS}${METHOD}Body(byte major, byte minor, ByteBuffer buffer) throws AMQFrameDecodingException
{
+ this(major, minor, getClazz(major,minor), getMethod(major,minor), buffer);
+ }
+
+ public ${CLASS}${METHOD}Body(byte major, byte minor, int clazzID, int methodID, ByteBuffer buffer) throws AMQFrameDecodingException
+ {
+
super(major, minor);
- _clazz = getClazz(major,minor);
- _method = getMethod(major,minor);
+ _clazz = clazzID;
+ _method = methodID;
%{FLIST} ${mb_field_decode}
}
- public ${CLASS}${METHOD}Body(byte major, byte minor
+ public ${CLASS}${METHOD}Body(byte major, byte minor, int clazzID, int methodID
%{FLIST} ${mb_field_parameter_list}
)
{
@@ -149,7 +161,19 @@ public class ${CLASS}${METHOD}Body extends AMQMethodBody implements EncodableAMQ
%{FLIST} ${mb_field_parameter_list}
)
{
- ${CLASS}${METHOD}Body body = new ${CLASS}${METHOD}Body(major, minor
+ return createAMQFrame(channelId, major, minor, getClazz(major,minor), getMethod(major,minor)
+%{FLIST} ${mb_field_passed_parameter_list}
+ );
+
+
+
+ }
+
+ public static AMQFrame createAMQFrame(int channelId, byte major, byte minor, int clazzID, int methodID
+%{FLIST} ${mb_field_parameter_list}
+ )
+ {
+ ${CLASS}${METHOD}Body body = new ${CLASS}${METHOD}Body(major, minor, clazzID, methodID
%{FLIST} ${mb_field_passed_parameter_list}
);
@@ -157,4 +181,5 @@ public class ${CLASS}${METHOD}Body extends AMQMethodBody implements EncodableAMQ
AMQFrame frame = new AMQFrame(channelId, body);
return frame;
}
+
}
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);
- }
-
}