You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2007/11/24 22:14:23 UTC
svn commit: r597918 [7/12] - in /incubator/qpid/branches/M2.1: gentools/
gentools/lib/ gentools/src/org/apache/qpid/gentools/ java/
java/broker/src/main/java/org/apache/qpid/server/
java/broker/src/main/java/org/apache/qpid/server/handler/ java/broker/...
Modified: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/LanguageConverter.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/LanguageConverter.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/LanguageConverter.java (original)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/LanguageConverter.java Sat Nov 24 13:14:14 2007
@@ -22,18 +22,21 @@
public interface LanguageConverter
{
- public void setDomainMap(AmqpDomainMap domainMap);
- public AmqpDomainMap getDomainMap();
- public void setConstantSet(AmqpConstantSet constantSet);
- public AmqpConstantSet getConstantSet();
-
- public void setModel(AmqpModel model);
- public AmqpModel getModel();
-
- public String prepareClassName(String className);
- public String prepareMethodName(String methodName);
- public String prepareDomainName(String domainName);
- public String getDomainType(String domainName, AmqpVersion version) throws AmqpTypeMappingException;
- public String getGeneratedType(String domainName, AmqpVersion version) throws AmqpTypeMappingException;
+// public AmqpDomainMap getDomainMap();
+// public AmqpConstantSet getConstantSet();
+// public AmqpModel getModel();
+
+ //
+ public String prepareClassName(String className);
+
+ public String prepareMethodName(String methodName);
+
+ public String prepareDomainName(String domainName);
+
+ public String getDomainType(String domainName, AmqpVersion version);
+
+ public String getGeneratedType(String domainName, AmqpVersion version);
+
+ public String prepareConstantName(String constantName);
}
Modified: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Main.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Main.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Main.java (original)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Main.java Sat Nov 24 13:14:14 2007
@@ -20,143 +20,149 @@
*/
package org.apache.qpid.gentools;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
+import org.apache.velocity.app.Velocity;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Properties;
public class Main
{
- private static final String defaultOutDir = ".." + Utils.fileSeparator + "gen";
- private static final String defaultCppTemplateDir = ".." + Utils.fileSeparator + "templ.cpp";
- private static final String defaultDotnetTemplateDir = ".." + Utils.fileSeparator + "templ.net";
- private static final String defaultJavaTemplateDir = ".." + Utils.fileSeparator + "templ.java";
-
- private enum GeneratorLangEnum { CPP, DOTNET, JAVA }
-
- private DocumentBuilder docBuilder;
- private AmqpVersionSet versionSet;
- private Generator generator;
- private AmqpConstantSet constants;
- private AmqpDomainMap domainMap;
- private AmqpModel model;
-
+ private static final String DEFAULT_OUTPUT_DIR = ".." + Utils.FILE_SEPARATOR + "gen";
+ private static final String DEFAULT_TEMPLATE_DIR_BASE = ".." + Utils.FILE_SEPARATOR;
+
+ private enum GeneratedLanguage
+ {
+ CPP(".cpp", CppGenerator.getFactory()),
+ DOTNET(".net", DotnetGenerator.getFactory()),
+ JAVA(".java", JavaGenerator.getFactory());
+
+ private final String _suffix;
+ private final Generator.Factory _factory;
+
+
+ private final String _defaultTemplateDirectory;
+
+ GeneratedLanguage(String suffix, Generator.Factory factory)
+ {
+ _suffix = suffix;
+ _factory = factory;
+ _defaultTemplateDirectory = DEFAULT_TEMPLATE_DIR_BASE + "templ" + _suffix;
+ }
+
+ public String getSuffix()
+ {
+ return _suffix;
+ }
+
+ public Generator newGenerator()
+ {
+ return _factory.newInstance();
+ }
+
+ public String getDefaultTemplateDirectory()
+ {
+ return _defaultTemplateDirectory;
+ }
+ }
+
+ private Generator generator;
+
private String outDir;
private String tmplDir;
- private GeneratorLangEnum generatorLang;
+ private GeneratedLanguage _generatorLang;
private ArrayList<String> xmlFiles;
- private File[] modelTemplateFiles;
- private File[] classTemplateFiles;
- private File[] methodTemplateFiles;
- private File[] fieldTemplateFiles;
-
- public Main() throws ParserConfigurationException
- {
- docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- versionSet = new AmqpVersionSet();
+
+ public Main()
+ {
xmlFiles = new ArrayList<String>();
- }
-
- public void run(String[] args)
- throws IOException,
- SAXException,
- AmqpParseException,
- AmqpTypeMappingException,
- AmqpTemplateException,
- TargetDirectoryException,
- IllegalAccessException,
- InvocationTargetException
- {
- modelTemplateFiles = new File[]{};
- classTemplateFiles = new File[]{};
- methodTemplateFiles = new File[]{};
- fieldTemplateFiles = new File[]{};
-
+ }
+
+ public void run(String[] args)
+ throws Exception,
+ SAXException,
+ AmqpParseException,
+ AmqpTypeMappingException,
+ AmqpTemplateException,
+ TargetDirectoryException,
+ IllegalAccessException,
+ InvocationTargetException, ParserConfigurationException
+ {
+
// 0. Initialize
- outDir = defaultOutDir;
+ outDir = DEFAULT_OUTPUT_DIR;
tmplDir = null;
- generatorLang = GeneratorLangEnum.CPP; // Default generation language
+ _generatorLang = GeneratedLanguage.CPP; // Default generation language
xmlFiles.clear();
processArgs(args);
- switch (generatorLang)
+
+ if (tmplDir == null)
{
- case JAVA:
- prepareJava();
- break;
- case DOTNET:
- prepareDotnet();
- break;
- default:
- prepareCpp();
+ tmplDir = _generatorLang.getDefaultTemplateDirectory();
}
- if (modelTemplateFiles.length == 0 && classTemplateFiles.length == 0 &&
- methodTemplateFiles.length == 0 && fieldTemplateFiles.length == 0)
- System.err.println(" WARNING: No template files.");
-
- // 1. Suck in all the XML spec files provided on the command line
+
+ generator = _generatorLang.newGenerator();
+ generator.setTemplateDirectory(tmplDir);
+ generator.setOutputDirectory(outDir);
+
+ // 1. Suck in all the XML spec files provided on the command line
analyzeXML();
-
- // 2. Load up all templates
- try
- {
- generator.initializeTemplates(modelTemplateFiles, classTemplateFiles,
- methodTemplateFiles, fieldTemplateFiles);
- }
- catch (FileNotFoundException e)
- {
- System.err.println("Error: Unable to load template file (check -t option on command-line):");
- System.err.println(e.getMessage());
- return;
- }
-
- // 3. Generate output
- generator.generate(new File(outDir));
-
- System.out.println("Files generated: " + generator.getNumberGeneratedFiles());
- System.out.println("Done.");
- }
+
+ Properties p = new Properties();
+ p.setProperty("file.resource.loader.path", tmplDir);
+
+ Velocity.init(p);
+
+ // 2. Load up all templates
+ generator.initializeTemplates();
+
+ // 3. Generate output
+ generator.generate();
+
+ System.out.println("Files generated: " + generator.getNumberGeneratedFiles());
+ System.out.println("Done.");
+ }
private void processArgs(String[] args)
{
// Crude but simple...
- for (int i=0; i<args.length; i++)
+ for (int i = 0; i < args.length; i++)
{
String arg = args[i];
if (arg.charAt(0) == '-')
{
switch (arg.charAt(1))
{
- case 'c':
- case 'C':
- generatorLang = GeneratorLangEnum.CPP;
+ case'c':
+ case'C':
+ _generatorLang = GeneratedLanguage.CPP;
break;
- case 'j':
- case 'J':
- generatorLang = GeneratorLangEnum.JAVA;
+ case'j':
+ case'J':
+ _generatorLang = GeneratedLanguage.JAVA;
break;
- case 'n':
- case 'N':
- generatorLang = GeneratorLangEnum.DOTNET;
+ case'n':
+ case'N':
+ _generatorLang = GeneratedLanguage.DOTNET;
break;
- case 'o':
- case 'O':
+ case'o':
+ case'O':
if (++i < args.length)
{
outDir = args[i];
}
- break;
- case 't':
- case 'T':
+ break;
+ case't':
+ case'T':
if (++i < args.length)
{
tmplDir = args[i];
@@ -170,87 +176,12 @@
}
}
}
-
- private void prepareJava()
- {
- if (tmplDir == null)
- tmplDir = defaultJavaTemplateDir;
- System.out.println("Java generation mode.");
- generator = new JavaGenerator(versionSet);
- constants = new AmqpConstantSet(generator);
- domainMap = new AmqpDomainMap(generator);
- model = new AmqpModel(generator);
- modelTemplateFiles = new File[]
- {
- new File(tmplDir + Utils.fileSeparator + "MethodRegistryClass.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AmqpConstantsClass.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "ProtocolVersionListClass.tmpl")
- };
- classTemplateFiles = new File[]
- {
-// new File(tmplDir + Utils.fileSeparator + "PropertyContentHeaderClass.tmpl")
- };
- methodTemplateFiles = new File[]
- {
- new File(tmplDir + Utils.fileSeparator + "MethodBodyClass.tmpl")
- };
- }
-
- private void prepareDotnet()
- {
- if (tmplDir == null)
- tmplDir = defaultDotnetTemplateDir;
- System.out.println(".NET generation mode.");
- generator = new DotnetGenerator(versionSet);
- constants = new AmqpConstantSet(generator);
- domainMap = new AmqpDomainMap(generator);
- model = new AmqpModel(generator);
- // TODO: Add templated that should be handled in here...
- modelTemplateFiles = new File[]
- {
-// new File(tmplDir + Utils.fileSeparator + "XXXClass.tmpl"),
- };
- classTemplateFiles = new File[]
- {
-// new File(tmplDir + Utils.fileSeparator + "XXXClass.tmpl"),
- };
- methodTemplateFiles = new File[]
- {
-// new File(tmplDir + Utils.fileSeparator + "XXXClass.tmpl"),
- };
- }
-
- private void prepareCpp()
- {
- if (tmplDir == null)
- tmplDir = defaultCppTemplateDir;
- System.out.println("C++ generation mode.");
- generator = new CppGenerator(versionSet);
- constants = new AmqpConstantSet(generator);
- domainMap = new AmqpDomainMap(generator);
- model = new AmqpModel(generator);
- modelTemplateFiles = new File[]
- {
- new File(tmplDir + Utils.fileSeparator + "AMQP_ServerOperations.h.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_ClientOperations.h.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_ServerProxy.h.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_ClientProxy.h.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_ServerProxy.cpp.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_ClientProxy.cpp.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_Constants.h.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_MethodVersionMap.h.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_MethodVersionMap.cpp.tmpl"),
- new File(tmplDir + Utils.fileSeparator + "AMQP_HighestVersion.h.tmpl")
- };
- methodTemplateFiles = new File[]
- {
- new File(tmplDir + Utils.fileSeparator + "MethodBodyClass.h.tmpl")
- };
- }
private void analyzeXML()
- throws IOException, SAXException, AmqpParseException, AmqpTypeMappingException
+ throws IOException, SAXException, AmqpParseException, AmqpTypeMappingException, ParserConfigurationException
{
+ DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
System.out.println("XML files: " + xmlFiles);
for (String filename : xmlFiles)
{
@@ -261,25 +192,21 @@
System.out.print(" \"" + filename + "\":");
Document doc = docBuilder.parse(new File(filename));
Node amqpNode = Utils.findChild(doc, Utils.ELEMENT_AMQP);
-
+
// 1b. Extract version (major and minor) from the XML file
int major = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MAJOR);
int minor = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MINOR);
AmqpVersion version = new AmqpVersion(major, minor);
System.out.println(" Found version " + version.toString() + ".");
- versionSet.add(version);
-
- // 1c. Extract domains
- constants.addFromNode(amqpNode, 0, version);
-
- // 1d. Extract domains
- domainMap.addFromNode(amqpNode, 0, version);
-
- // 1e. Extract class/method/field heirarchy
- model.addFromNode(amqpNode, 0, version);
+ generator.addVersion(version);
+ generator.addFromNode(amqpNode, version);
+
+
}
else
+ {
System.err.println("ERROR: AMQP XML file \"" + filename + "\" not found.");
+ }
}
// *** DEBUG INFO *** Uncomment bits from this block to see lots of stuff....
// System.out.println();
@@ -296,58 +223,79 @@
// System.out.println("*** End debug output ***");
// System.out.println();
}
-
- public static void main(String[] args)
- {
- int exitCode = 1;
- // TODO: This is a simple and klunky way of hangling command-line args, and could be improved upon.
- if (args.length < 2)
- {
- usage();
- }
- else
- {
- try
- {
- new Main().run(args);
- exitCode = 0;
- }
- catch (IOException e) { e.printStackTrace(); }
- catch (ParserConfigurationException e) { e.printStackTrace(); }
- catch (SAXException e) { e.printStackTrace(); }
- catch (AmqpParseException e) { e.printStackTrace(); }
- catch (AmqpTypeMappingException e) { e.printStackTrace(); }
- catch (AmqpTemplateException e) { e.printStackTrace(); }
- catch (TargetDirectoryException e) { e.printStackTrace(); }
- catch (IllegalAccessException e) { e.printStackTrace(); }
- catch (InvocationTargetException e) { e.printStackTrace(); }
- }
- System.exit(exitCode);
- }
-
- public static void usage()
- {
- System.out.println("AMQP XML generator v.0.0");
- System.out.println("Usage: Main -c|-j [-o outDir] [-t tmplDir] XMLfile [XMLfile ...]");
- System.out.println(" where -c: Generate C++.");
- System.out.println(" -j: Generate Java.");
- System.out.println(" -n: Generate .NET.");
- System.out.println(" -o outDir: Use outDir as the output dir (default=\"" + defaultOutDir + "\").");
+
+ public static void main(String[] args)
+ {
+ int exitCode = 1;
+ // TODO: This is a simple and klunky way of hangling command-line args, and could be improved upon.
+ if (args.length < 2)
+ {
+ usage();
+ }
+ else
+ {
+ try
+ {
+ new Main().run(args);
+ exitCode = 0;
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ catch (ParserConfigurationException e)
+ {
+ e.printStackTrace();
+ }
+ catch (SAXException e)
+ {
+ e.printStackTrace();
+ }
+ catch (AmqpParseException e)
+ {
+ e.printStackTrace();
+ }
+ catch (AmqpTypeMappingException e)
+ {
+ e.printStackTrace();
+ }
+ catch (AmqpTemplateException e)
+ {
+ e.printStackTrace();
+ }
+ catch (TargetDirectoryException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IllegalAccessException e)
+ {
+ e.printStackTrace();
+ }
+ catch (InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ System.exit(exitCode);
+ }
+
+ public static void usage()
+ {
+ System.out.println("AMQP XML generator v.0.0");
+ System.out.println("Usage: Main -c|-j [-o outDir] [-t tmplDir] XMLfile [XMLfile ...]");
+ System.out.println(" where -c: Generate C++.");
+ System.out.println(" -j: Generate Java.");
+ System.out.println(" -n: Generate .NET.");
+ System.out.println(" -o outDir: Use outDir as the output dir (default=\"" + DEFAULT_OUTPUT_DIR + "\").");
System.out.println(" -t tmplDir: Find templates in tmplDir.");
- System.out.println(" Defaults: \"" + defaultCppTemplateDir + "\" for C++;");
- System.out.println(" \"" + defaultJavaTemplateDir + "\" for java.");
- System.out.println(" XMLfile is a space-separated list of AMQP XML files to be parsed.");
- }
-
- public static String ListTemplateList(File[] list)
- {
- StringBuffer sb = new StringBuffer();
- for (int i=0; i<list.length; i++)
- {
- if (i != 0)
- sb.append(", ");
- sb.append(list[i].getName());
- }
- return sb.toString();
- }
+ System.out.println(" Defaults: \"" + GeneratedLanguage.CPP.getDefaultTemplateDirectory() + "\" for C++;");
+ System.out.println(" \"" + GeneratedLanguage.JAVA.getDefaultTemplateDirectory() + "\" for java.;");
+ System.out.println(" \"" + GeneratedLanguage.DOTNET.getDefaultTemplateDirectory() + "\" for .NET.");
+ System.out.println(" XMLfile is a space-separated list of AMQP XML files to be parsed.");
+ }
+
}
Added: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java?rev=597918&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java (added)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java Sat Nov 24 13:14:14 2007
@@ -0,0 +1,26 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+public interface MangledGenerateMethod
+{
+ String generate(AmqpField field, int indentSize, int tabSize, boolean notLast);
+}
Modified: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/NodeAware.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/NodeAware.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/NodeAware.java (original)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/NodeAware.java Sat Nov 24 13:14:14 2007
@@ -24,23 +24,24 @@
/**
* @author kpvdr
- * Interface allowing the addition of elements from a node in the
- * DOM of the AMQP specification. It is used by each of the model
- * elements in a recursive fashion to build the model.
+ * Interface allowing the addition of elements from a node in the
+ * DOM of the AMQP specification. It is used by each of the model
+ * elements in a recursive fashion to build the model.
*/
public interface NodeAware
{
- /**
- * Add a model element from the current DOM node. All model elements must implement
- * this interface. If the node contains children that are also a part of the model,
- * then this method is called on new instances of those model elements.
- * @param n Node from which the current model element is to be added.
- * @param o Ordinal value of the current model elemet.
- * @param v Verion of the DOM from which the node comes.
- * @throws AmqpParseException
- * @throws AmqpTypeMappingException
- * @returns true if a node was added, false if not
- */
- public boolean addFromNode(Node n, int o, AmqpVersion v)
- throws AmqpParseException, AmqpTypeMappingException;
+ /**
+ * Add a model element from the current DOM node. All model elements must implement
+ * this interface. If the node contains children that are also a part of the model,
+ * then this method is called on new instances of those model elements.
+ *
+ * @param n Node from which the current model element is to be added.
+ * @param o Ordinal value of the current model elemet.
+ * @param v Verion of the DOM from which the node comes.
+ * @throws AmqpParseException
+ * @throws AmqpTypeMappingException
+ * @returns true if a node was added, false if not
+ */
+ public boolean addFromNode(Node n, int o, AmqpVersion v)
+ throws AmqpParseException, AmqpTypeMappingException;
}
Modified: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Printable.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Printable.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Printable.java (original)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Printable.java Sat Nov 24 13:14:14 2007
@@ -24,5 +24,5 @@
public interface Printable
{
- public void print(PrintStream out, int marginSize, int tabSize);
+ public void print(PrintStream out, int marginSize, int tabSize);
}
Added: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java?rev=597918&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java (added)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java Sat Nov 24 13:14:14 2007
@@ -0,0 +1,103 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map.Entry;
+
+
+public class SingleVersionClass
+{
+ private final int _classId;
+
+
+ private final AmqpClass _amqpClass;
+ private final AmqpVersion _amqpVersion;
+ private final Generator _generator;
+ private final List<SingleVersionMethod> _methodList = new ArrayList<SingleVersionMethod>();
+
+ public SingleVersionClass(AmqpClass amqpClass, AmqpVersion amqpVersion, Generator generator)
+ {
+ _amqpClass = amqpClass;
+ _amqpVersion = amqpVersion;
+ _generator = generator;
+
+ AmqpOrdinalVersionMap indexMap = amqpClass.getIndexMap();
+ int classId = 0;
+ for(Entry<Integer, AmqpVersionSet> entry : indexMap.entrySet())
+ {
+ if(entry.getValue().contains(_amqpVersion))
+ {
+ classId = entry.getKey();
+ break;
+ }
+ }
+ _classId = classId;
+
+
+ Collection<AmqpMethod> methods = _amqpClass.getMethodMap().values();
+
+ for(AmqpMethod amqpMethod : methods)
+ {
+ _methodList.add(new SingleVersionMethod(amqpMethod, _amqpVersion, _generator));
+
+ }
+
+ Collections.sort(_methodList, new Comparator<SingleVersionMethod>(){
+ public int compare(SingleVersionMethod method1, SingleVersionMethod method2)
+ {
+ return method1.getMethodId() - method2.getMethodId();
+ }
+ });
+
+
+ }
+
+ public int getClassId()
+ {
+ return _classId;
+ }
+
+ public String getName()
+ {
+ return _amqpClass.getName();
+ }
+
+
+
+
+
+ public List<SingleVersionMethod> getMethodList()
+ {
+ return _methodList;
+ }
+
+
+ public int getMaximumMethodId()
+ {
+ return _methodList.get(_methodList.size()-1).getMethodId();
+ }
+}
Added: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionField.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionField.java?rev=597918&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionField.java (added)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionField.java Sat Nov 24 13:14:14 2007
@@ -0,0 +1,68 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+
+public class SingleVersionField
+{
+ private final AmqpField _field;
+ private final AmqpVersion _amqpVersion;
+ private final Generator _generator;
+
+ public SingleVersionField(AmqpField field, AmqpVersion amqpVersion, Generator generator)
+ {
+ _field = field;
+ _amqpVersion = amqpVersion;
+ _generator = generator;
+ }
+
+ public String getName()
+ {
+ return _field.getName();
+ }
+
+ public String getDomain()
+ {
+ return _field.getDomain(_amqpVersion);
+ }
+
+
+ public String getDomainType()
+ {
+ return _generator.getDomainType(_field.getDomain(_amqpVersion),_amqpVersion);
+ }
+
+ public String getNativeType()
+ {
+ return _generator.getNativeType(getDomainType());
+ }
+
+ public String getEncodingType()
+ {
+ return _generator.getEncodingType(getDomainType());
+ }
+
+
+ public int getPosition()
+ {
+ return _field.getOrdinal(_amqpVersion);
+ }
+}
Added: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java?rev=597918&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java (added)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java Sat Nov 24 13:14:14 2007
@@ -0,0 +1,154 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+import java.util.Map.Entry;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+public class SingleVersionMethod
+{
+ private final AmqpMethod _amqpMethod;
+ private final AmqpVersion _amqpVersion;
+ private final int _methodId;
+ private final List<SingleVersionField> _fieldList = new ArrayList<SingleVersionField>();
+ private final Generator _generator;
+ private final List<ConsolidatedField> _consolidatedFields = new ArrayList<ConsolidatedField>();
+ private final Map<String, ConsolidatedField> _fieldNameToConsolidatedFieldMap = new HashMap<String, ConsolidatedField>();
+
+
+ public SingleVersionMethod(AmqpMethod amqpMethod, AmqpVersion amqpVersion, Generator generator)
+ {
+ _amqpMethod = amqpMethod;
+ _amqpVersion = amqpVersion;
+ _generator = generator;
+
+ AmqpOrdinalVersionMap indexMap = amqpMethod.getIndexMap();
+ int methodId = 0;
+ for(Entry<Integer, AmqpVersionSet> entry : indexMap.entrySet())
+ {
+ if(entry.getValue().contains(_amqpVersion))
+ {
+ methodId = entry.getKey();
+ break;
+ }
+ }
+ _methodId = methodId;
+
+ Collection<AmqpField> fields = _amqpMethod.getFieldMap().values();
+
+ for(AmqpField field : fields)
+ {
+ _fieldList.add(new SingleVersionField(field, _amqpVersion, _generator));
+
+ }
+
+ Collections.sort(_fieldList, new Comparator<SingleVersionField>(){
+ public int compare(SingleVersionField field1, SingleVersionField field2)
+ {
+ return field1.getPosition() - field2.getPosition();
+ }
+ });
+
+
+
+ ConsolidatedField lastField = null;
+ int bitfieldNum = 0;
+ for(SingleVersionField field : _fieldList)
+ {
+ String domainType = field.getDomainType();
+ if(!domainType.equals("bit"))
+ {
+ lastField = new ConsolidatedField(_generator,
+ field.getName(),
+ field.getDomainType());
+ _consolidatedFields.add(lastField);
+ }
+ else if(lastField == null || !lastField.getType().equals("bitfield"))
+ {
+ lastField = new ConsolidatedField(_generator,
+ domainType.equals("bit") ? "bitfield"+bitfieldNum++ : field.getName(),
+ domainType.equals("bit") ? "bitfield" : field.getDomainType(),
+ field.getName());
+ _consolidatedFields.add(lastField);
+ }
+ else
+ {
+ lastField.add(field.getName());
+ }
+ _fieldNameToConsolidatedFieldMap.put(field.getName(), lastField);
+
+ }
+ }
+
+ public int getMethodId()
+ {
+ return _methodId;
+ }
+
+ public String getName()
+ {
+ return _amqpMethod.getName();
+ }
+
+ public Collection<SingleVersionField> getFieldList()
+ {
+ return Collections.unmodifiableCollection(_fieldList);
+ }
+
+ public List<ConsolidatedField> getConsolidatedFields()
+ {
+ return _consolidatedFields;
+ }
+
+ public String getConsolidatedFieldName(String fieldName)
+ {
+ return _fieldNameToConsolidatedFieldMap.get(fieldName).getName();
+ }
+
+ public boolean isConsolidated(String fieldName)
+ {
+ return _fieldNameToConsolidatedFieldMap.get(fieldName).isConsolidated();
+ }
+
+ public int getPositionInBitField(String fieldName)
+ {
+ return _fieldNameToConsolidatedFieldMap.get(fieldName).getPosition(fieldName);
+ }
+
+
+ public boolean isServerMethod()
+ {
+ return _amqpMethod.isServerMethod(_amqpVersion);
+ }
+
+
+ public boolean isClientMethod()
+ {
+ return _amqpMethod.isClientMethod(_amqpVersion);
+ }
+
+}
Added: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java?rev=597918&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java (added)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java Sat Nov 24 13:14:14 2007
@@ -0,0 +1,71 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.gentools;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+
+public class SingleVersionModel
+{
+ private final AmqpModel _amqpModel;
+ private final AmqpVersion _amqpVersion;
+ private final Generator _generator;
+ private final List<SingleVersionClass> _classList = new ArrayList<SingleVersionClass>();
+
+ public SingleVersionModel(AmqpModel amqpModel, AmqpVersion amqpVersion, Generator generator)
+ {
+ _amqpModel = amqpModel;
+ _amqpVersion = amqpVersion;
+ _generator = generator;
+
+
+ Collection<AmqpClass> originalClasses = _amqpModel.getClassMap().values();
+
+ for(AmqpClass amqpClass : originalClasses)
+ {
+ _classList.add(new SingleVersionClass(amqpClass, _amqpVersion, _generator));
+
+ }
+
+ Collections.sort(_classList, new Comparator<SingleVersionClass>(){
+ public int compare(SingleVersionClass amqpClass1, SingleVersionClass amqpClass2)
+ {
+ return amqpClass1.getClassId() - amqpClass2.getClassId();
+ }
+ });
+
+
+ }
+
+ public Collection<SingleVersionClass> getClassList()
+ {
+ return Collections.unmodifiableCollection(_classList);
+ }
+
+ public int getMaximumClassId()
+ {
+ return _classList.get(_classList.size()-1).getClassId();
+ }
+}
Modified: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java (original)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java Sat Nov 24 13:14:14 2007
@@ -21,10 +21,10 @@
package org.apache.qpid.gentools;
@SuppressWarnings("serial")
-public class TargetDirectoryException extends Exception
+public class TargetDirectoryException extends RuntimeException
{
- public TargetDirectoryException(String msg)
- {
- super(msg);
- }
+ public TargetDirectoryException(String msg)
+ {
+ super(msg);
+ }
}
Modified: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Utils.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Utils.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Utils.java (original)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/Utils.java Sat Nov 24 13:14:14 2007
@@ -21,103 +21,114 @@
package org.apache.qpid.gentools;
import org.w3c.dom.Attr;
-//import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Utils
{
- public final static String fileSeparator = System.getProperty("file.separator");
- public final static String lineSeparator = System.getProperty("line.separator");
-
- public final static String ATTRIBUTE_NAME = "name";
- public final static String ATTRIBUTE_MAJOR = "major";
- public final static String ATTRIBUTE_MINOR = "minor";
- public final static String ATTRIBUTE_INDEX = "index";
- public final static String ATTRIBUTE_LABEL = "label";
- public final static String ATTRIBUTE_SYNCHRONOUS = "synchronous";
- public final static String ATTRIBUTE_CONTENT = "content";
- public final static String ATTRIBUTE_HANDLER = "handler";
- public final static String ATTRIBUTE_DOMAIN = "domain";
+ public final static String FILE_SEPARATOR = System.getProperty("file.separator");
+ public final static String LINE_SEPARATOR = System.getProperty("line.separator");
+
+ public final static String ATTRIBUTE_NAME = "name";
+ public final static String ATTRIBUTE_MAJOR = "major";
+ public final static String ATTRIBUTE_MINOR = "minor";
+ public final static String ATTRIBUTE_INDEX = "index";
+ public final static String ATTRIBUTE_LABEL = "label";
+ public final static String ATTRIBUTE_SYNCHRONOUS = "synchronous";
+ public final static String ATTRIBUTE_CONTENT = "content";
+ public final static String ATTRIBUTE_HANDLER = "handler";
+ public final static String ATTRIBUTE_DOMAIN = "domain";
public final static String ATTRIBUTE_VALUE = "value";
- public final static String ATTRIBUTE_TYPE = "type"; // For compatibility with AMQP 8.0
-
- public final static String ELEMENT_AMQP = "amqp";
- public final static String ELEMENT_CHASSIS = "chassis";
- public final static String ELEMENT_CLASS = "class";
- public final static String ELEMENT_CODEGEN = "codegen";
+ public final static String ATTRIBUTE_TYPE = "type"; // For compatibility with AMQP 8.0
+
+ public final static String ELEMENT_AMQP = "amqp";
+ public final static String ELEMENT_CHASSIS = "chassis";
+ public final static String ELEMENT_CLASS = "class";
+ public final static String ELEMENT_CODEGEN = "codegen";
public final static String ELEMENT_CONSTANT = "constant";
- public final static String ELEMENT_DOMAIN = "domain";
- public final static String ELEMENT_METHOD = "method";
- public final static String ELEMENT_FIELD = "field";
- public final static String ELEMENT_VERSION = "version";
-
- // Attribute functions
-
- public static String getNamedAttribute(Node n, String attrName) throws AmqpParseException
- {
- NamedNodeMap nnm = n.getAttributes();
- if (nnm == null)
- throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attributes.");
- Attr a = (Attr)nnm.getNamedItem(attrName);
- if (a == null)
- throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attribute \"" + attrName + "\".");
- return a.getNodeValue();
- }
-
- public static int getNamedIntegerAttribute(Node n, String attrName) throws AmqpParseException
- {
- return Integer.parseInt(getNamedAttribute(n, attrName));
- }
-
- // Element functions
-
- public static Node findChild(Node n, String eltName) throws AmqpParseException
- {
- NodeList nl = n.getChildNodes();
- for (int i=0; i<nl.getLength(); i++)
- {
- Node cn = nl.item(i);
- if (cn.getNodeName().compareTo(eltName) == 0)
- return cn;
- }
- throw new AmqpParseException("Node \"" + n.getNodeName() +
- "\" does not contain child element \"" + eltName + "\".");
- }
-
- // String functions
-
- public static String firstUpper(String str)
- {
- if (!Character.isLowerCase(str.charAt(0)))
- return str;
- StringBuffer sb = new StringBuffer(str);
- sb.setCharAt(0, Character.toUpperCase(str.charAt(0)));
- return sb.toString();
- }
-
- public static String firstLower(String str)
- {
- if (!Character.isUpperCase(str.charAt(0)))
- return str;
- StringBuffer sb = new StringBuffer(str);
- sb.setCharAt(0, Character.toLowerCase(str.charAt(0)));
- return sb.toString();
- }
-
- public static String createSpaces(int cnt)
- {
- StringBuffer sb = new StringBuffer();
- for (int i=0; i<cnt; i++)
- sb.append(' ');
- return sb.toString();
- }
-
+ public final static String ELEMENT_DOMAIN = "domain";
+ public final static String ELEMENT_METHOD = "method";
+ public final static String ELEMENT_FIELD = "field";
+ public final static String ELEMENT_VERSION = "version";
+
+ // Attribute functions
+
+ public static String getNamedAttribute(Node n, String attrName) throws AmqpParseException
+ {
+ NamedNodeMap nnm = n.getAttributes();
+ if (nnm == null)
+ {
+ throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attributes.");
+ }
+ Attr a = (Attr) nnm.getNamedItem(attrName);
+ if (a == null)
+ {
+ throw new AmqpParseException("Node \"" + n.getNodeName() + "\" has no attribute \"" + attrName + "\".");
+ }
+ return a.getNodeValue();
+ }
+
+ public static int getNamedIntegerAttribute(Node n, String attrName) throws AmqpParseException
+ {
+ return Integer.parseInt(getNamedAttribute(n, attrName));
+ }
+
+ // Element functions
+
+ public static Node findChild(Node n, String eltName) throws AmqpParseException
+ {
+ NodeList nl = n.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node cn = nl.item(i);
+ if (cn.getNodeName().compareTo(eltName) == 0)
+ {
+ return cn;
+ }
+ }
+ throw new AmqpParseException("Node \"" + n.getNodeName() +
+ "\" does not contain child element \"" + eltName + "\".");
+ }
+
+ // String functions
+
+ public static String firstUpper(String str)
+ {
+ if (!Character.isLetter(str.charAt(0)) || !Character.isLowerCase(str.charAt(0)))
+ {
+ return str;
+ }
+ StringBuffer sb = new StringBuffer(str);
+ sb.setCharAt(0, Character.toUpperCase(str.charAt(0)));
+ return sb.toString();
+ }
+
+ public static String firstLower(String str)
+ {
+ if (!Character.isUpperCase(str.charAt(0)))
+ {
+ return str;
+ }
+ StringBuffer sb = new StringBuffer(str);
+ sb.setCharAt(0, Character.toLowerCase(str.charAt(0)));
+ return sb.toString();
+ }
+
+ public static String createSpaces(int cnt)
+ {
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < cnt; i++)
+ {
+ sb.append(' ');
+ }
+ return sb.toString();
+ }
+
public static boolean containsOnlyDigits(String str)
{
boolean foundNonDigit = false;
- for (int i=0; i<str.length() && !foundNonDigit; i++)
+ for (int i = 0; i < str.length() && !foundNonDigit; i++)
{
if (!Character.isDigit(str.charAt(i)))
{
@@ -126,12 +137,12 @@
}
return !foundNonDigit;
}
-
+
public static boolean containsOnlyDigitsAndDecimal(String str)
{
boolean foundNonDigit = false;
int decimalCntr = 0;
- for (int i=0; i<str.length() && !foundNonDigit && decimalCntr<2; i++)
+ for (int i = 0; i < str.length() && !foundNonDigit && decimalCntr < 2; i++)
{
char ch = str.charAt(i);
if (!(Character.isDigit(ch) || ch == '.'))
@@ -139,8 +150,10 @@
foundNonDigit = true;
}
else if (ch == '.')
+ {
decimalCntr++;
+ }
}
- return !foundNonDigit && decimalCntr<2;
+ return !foundNonDigit && decimalCntr < 2;
}
}
Modified: incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java (original)
+++ incubator/qpid/branches/M2.1/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java Sat Nov 24 13:14:14 2007
@@ -22,5 +22,5 @@
public interface VersionConsistencyCheck
{
- public boolean isVersionConsistent(AmqpVersionSet globalVersionSet);
+ public boolean isVersionConsistent(AmqpVersionSet globalVersionSet);
}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java Sat Nov 24 13:14:14 2007
@@ -266,8 +266,8 @@
// returns true iff the message was delivered (i.e. if all data was
// received
if (_currentMessage.addContentBodyFrame(_storeContext,
- protocolSession.getRegistry().getProtocolVersionMethodConverter().convertToContentChunk(
- contentBody)))
+ protocolSession.getMethodRegistry().getProtocolVersionMethodConverter().convertToContentChunk(
+ contentBody)))
{
// callback to allow the context to do any post message processing
// primary use is to allow message return processing in the non-tx case
Added: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/AccessRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/AccessRequestHandler.java?rev=597918&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/AccessRequestHandler.java (added)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/AccessRequestHandler.java Sat Nov 24 13:14:14 2007
@@ -0,0 +1,44 @@
+package org.apache.qpid.server.handler;
+
+import org.apache.qpid.framing.*;
+import org.apache.qpid.server.state.StateAwareMethodListener;
+import org.apache.qpid.server.state.AMQStateManager;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.queue.QueueRegistry;
+import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.AMQException;
+
+/**
+ * @author Apache Software Foundation
+ *
+ *
+ */
+public class AccessRequestHandler implements StateAwareMethodListener<AccessRequestBody>
+{
+ private static final AccessRequestHandler _instance = new AccessRequestHandler();
+
+
+ public static AccessRequestHandler getInstance()
+ {
+ return _instance;
+ }
+
+ private AccessRequestHandler()
+ {
+ }
+
+ public void methodReceived(AMQStateManager stateManager, AccessRequestBody body, int channelId) throws AMQException
+ {
+ AMQProtocolSession session = stateManager.getProtocolSession();
+
+ MethodRegistry methodRegistry = session.getMethodRegistry();
+
+ // We don't implement access control class, but to keep clients happy that expect it
+ // always use the "0" ticket.
+ AccessRequestOkBody response = methodRegistry.createAccessRequestOkBody(0);
+
+ session.writeFrame(response.generateFrame(channelId));
+ }
+}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicAckMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -44,24 +44,24 @@
{
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicAckBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicAckBody body, int channelId) throws AMQException
{
AMQProtocolSession protocolSession = stateManager.getProtocolSession();
- BasicAckBody body = evt.getMethod();
+
if (_log.isDebugEnabled())
{
- _log.debug("Ack(Tag:" + body.deliveryTag + ":Mult:" + body.multiple + ") received on channel " + evt.getChannelId());
+ _log.debug("Ack(Tag:" + body.getDeliveryTag() + ":Mult:" + body.getMultiple() + ") received on channel " + channelId);
}
- final AMQChannel channel = protocolSession.getChannel(evt.getChannelId());
+ final AMQChannel channel = protocolSession.getChannel(channelId);
if (channel == null)
{
- throw body.getChannelNotFoundException(evt.getChannelId());
+ throw body.getChannelNotFoundException(channelId);
}
// this method throws an AMQException if the delivery tag is not known
- channel.acknowledgeMessage(body.deliveryTag, body.multiple);
+ channel.acknowledgeMessage(body.getDeliveryTag(), body.getMultiple());
}
}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicCancelMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -24,6 +24,7 @@
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.BasicCancelBody;
import org.apache.qpid.framing.BasicCancelOkBody;
+import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.protocol.AMQProtocolSession;
@@ -46,34 +47,30 @@
{
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicCancelBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicCancelBody body, int channelId) throws AMQException
{
- AMQProtocolSession protocolSession = stateManager.getProtocolSession();
+ AMQProtocolSession session = stateManager.getProtocolSession();
+
+ final AMQChannel channel = session.getChannel(channelId);
- final AMQChannel channel = protocolSession.getChannel(evt.getChannelId());
- final BasicCancelBody body = evt.getMethod();
if (channel == null)
{
- throw body.getChannelNotFoundException(evt.getChannelId());
+ throw body.getChannelNotFoundException(channelId);
}
if (_log.isDebugEnabled())
{
- _log.debug("BasicCancel: for:" + body.consumerTag +
- " nowait:" + body.nowait);
+ _log.debug("BasicCancel: for:" + body.getConsumerTag() +
+ " nowait:" + body.getNowait());
}
- channel.unsubscribeConsumer(protocolSession, body.consumerTag);
- if (!body.nowait)
+ channel.unsubscribeConsumer(session, body.getConsumerTag());
+ if (!body.getNowait())
{
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- final AMQFrame responseFrame = BasicCancelOkBody.createAMQFrame(evt.getChannelId(),
- (byte) 8, (byte) 0, // AMQP version (major, minor)
- body.consumerTag); // consumerTag
- protocolSession.writeFrame(responseFrame);
+ MethodRegistry methodRegistry = session.getMethodRegistry();
+ BasicCancelOkBody cancelOkBody = methodRegistry.createBasicCancelOkBody(body.getConsumerTag());
+ session.writeFrame(cancelOkBody.generateFrame(channelId));
}
}
}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicConsumeMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -22,11 +22,7 @@
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.BasicConsumeBody;
-import org.apache.qpid.framing.BasicConsumeOkBody;
-import org.apache.qpid.framing.ChannelCloseBody;
-import org.apache.qpid.framing.ConnectionCloseBody;
+import org.apache.qpid.framing.*;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.AMQChannel;
@@ -52,12 +48,12 @@
{
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicConsumeBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicConsumeBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
- BasicConsumeBody body = evt.getMethod();
- final int channelId = evt.getChannelId();
+
+
AMQChannel channel = session.getChannel(channelId);
@@ -65,29 +61,29 @@
if (channel == null)
{
- throw body.getChannelNotFoundException(evt.getChannelId());
+ throw body.getChannelNotFoundException(channelId);
}
else
{
if (_log.isDebugEnabled())
{
- _log.debug("BasicConsume: from '" + body.queue +
- "' for:" + body.consumerTag +
- " nowait:" + body.nowait +
- " args:" + body.arguments);
+ _log.debug("BasicConsume: from '" + body.getQueue() +
+ "' for:" + body.getConsumerTag() +
+ " nowait:" + body.getNowait() +
+ " args:" + body.getArguments());
}
- AMQQueue queue = body.queue == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.queue);
+ AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.getQueue().intern());
if (queue == null)
{
if (_log.isTraceEnabled())
{
- _log.trace("No queue for '" + body.queue + "'");
+ _log.trace("No queue for '" + body.getQueue() + "'");
}
- if (body.queue != null)
+ if (body.getQueue() != null)
{
- String msg = "No such queue, '" + body.queue + "'";
+ String msg = "No such queue, '" + body.getQueue() + "'";
throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
}
else
@@ -99,23 +95,27 @@
else
{
- if (body.consumerTag != null)
+ final AMQShortString consumerTagName;
+
+ if (body.getConsumerTag() != null)
+ {
+ consumerTagName = body.getConsumerTag().intern();
+ }
+ else
{
- body.consumerTag = body.consumerTag.intern();
+ consumerTagName = null;
}
try
{
- AMQShortString consumerTag = channel.subscribeToQueue(body.consumerTag, queue, session, !body.noAck,
- body.arguments, body.noLocal, body.exclusive);
- if (!body.nowait)
+ AMQShortString consumerTag = channel.subscribeToQueue(consumerTagName, queue, session, !body.getNoAck(),
+ body.getArguments(), body.getNoLocal(), body.getExclusive());
+ if (!body.getNowait())
{
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- session.writeFrame(BasicConsumeOkBody.createAMQFrame(channelId,
- (byte) 8, (byte) 0, // AMQP version (major, minor)
- consumerTag)); // consumerTag
+ MethodRegistry methodRegistry = session.getMethodRegistry();
+ AMQMethodBody responseBody = methodRegistry.createBasicConsumeOkBody(consumerTag);
+ session.writeFrame(responseBody.generateFrame(channelId));
+
}
//now allow queue to start async processing of any backlog of messages
@@ -124,33 +124,26 @@
catch (org.apache.qpid.AMQInvalidArgumentException ise)
{
_log.debug("Closing connection due to invalid selector");
- // Why doesn't this ChannelException work.
-// throw body.getChannelException(AMQConstant.INVALID_ARGUMENT, ise.getMessage());
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- session.writeFrame(ChannelCloseBody.createAMQFrame(channelId,
- (byte) 8, (byte) 0, // AMQP version (major, minor)
- BasicConsumeBody.getClazz((byte) 8, (byte) 0), // classId
- BasicConsumeBody.getMethod((byte) 8, (byte) 0), // methodId
- AMQConstant.INVALID_ARGUMENT.getCode(), // replyCode
- new AMQShortString(ise.getMessage()))); // replyText
+
+ MethodRegistry methodRegistry = session.getMethodRegistry();
+ AMQMethodBody responseBody = methodRegistry.createChannelCloseBody(AMQConstant.INVALID_ARGUMENT.getCode(),
+ new AMQShortString(ise.getMessage()),
+ body.getClazz(),
+ body.getMethod());
+ session.writeFrame(responseBody.generateFrame(channelId));
+
+
}
catch (ConsumerTagNotUniqueException e)
{
- AMQShortString msg = new AMQShortString("Non-unique consumer tag, '" + body.consumerTag + "'");
- // If the above doesn't work then perhaps this is wrong too.
-// throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
-// "Non-unique consumer tag, '" + body.consumerTag + "'");
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- session.writeFrame(ConnectionCloseBody.createAMQFrame(channelId,
- (byte) 8, (byte) 0, // AMQP version (major, minor)
- BasicConsumeBody.getClazz((byte) 8, (byte) 0), // classId
- BasicConsumeBody.getMethod((byte) 8, (byte) 0), // methodId
- AMQConstant.NOT_ALLOWED.getCode(), // replyCode
- msg)); // replyText
+ AMQShortString msg = new AMQShortString("Non-unique consumer tag, '" + body.getConsumerTag() + "'");
+
+ MethodRegistry methodRegistry = session.getMethodRegistry();
+ AMQMethodBody responseBody = methodRegistry.createConnectionCloseBody(AMQConstant.NOT_ALLOWED.getCode(), // replyCode
+ msg, // replytext
+ body.getClazz(),
+ body.getMethod());
+ session.writeFrame(responseBody.generateFrame(0));
}
catch (AMQQueue.ExistingExclusiveSubscription e)
{
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicGetMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -25,6 +25,7 @@
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.BasicGetBody;
import org.apache.qpid.framing.BasicGetEmptyBody;
+import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.AMQChannel;
@@ -49,30 +50,29 @@
{
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicGetBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicGetBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
- BasicGetBody body = evt.getMethod();
- final int channelId = evt.getChannelId();
+
VirtualHost vHost = session.getVirtualHost();
AMQChannel channel = session.getChannel(channelId);
if (channel == null)
{
- throw body.getChannelNotFoundException(evt.getChannelId());
+ throw body.getChannelNotFoundException(channelId);
}
else
{
- AMQQueue queue = body.queue == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.queue);
+ AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.getQueue());
if (queue == null)
{
- _log.info("No queue for '" + body.queue + "'");
- if(body.queue!=null)
+ _log.info("No queue for '" + body.getQueue() + "'");
+ if(body.getQueue()!=null)
{
throw body.getConnectionException(AMQConstant.NOT_FOUND,
- "No such queue, '" + body.queue + "'");
+ "No such queue, '" + body.getQueue()+ "'");
}
else
{
@@ -82,12 +82,14 @@
}
else
{
- if(!queue.performGet(session, channel, !body.noAck))
+ if(!queue.performGet(session, channel, !body.getNoAck()))
{
+ MethodRegistry methodRegistry = session.getMethodRegistry();
+ // TODO - set clusterId
+ BasicGetEmptyBody responseBody = methodRegistry.createBasicGetEmptyBody(null);
- // TODO - set clusterId
- session.writeFrame(BasicGetEmptyBody.createAMQFrame(channelId, body.getMajor(), body.getMinor(), null));
+ session.writeFrame(responseBody.generateFrame(channelId));
}
}
}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicPublishMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -24,6 +24,8 @@
import org.apache.qpid.AMQException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.BasicPublishBody;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
@@ -50,29 +52,27 @@
{
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicPublishBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicPublishBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
- final BasicPublishBody body = evt.getMethod();
+
if (_log.isDebugEnabled())
{
- _log.debug("Publish received on channel " + evt.getChannelId());
+ _log.debug("Publish received on channel " + channelId);
}
+ AMQShortString exchange = body.getExchange();
// TODO: check the delivery tag field details - is it unique across the broker or per subscriber?
- if (body.exchange == null)
+ if (exchange == null)
{
- body.exchange = ExchangeDefaults.DEFAULT_EXCHANGE_NAME;
+ exchange = ExchangeDefaults.DEFAULT_EXCHANGE_NAME;
}
- else
- {
- body.exchange = body.exchange.intern();
- }
+
VirtualHost vHost = session.getVirtualHost();
- Exchange e = vHost.getExchangeRegistry().getExchange(body.exchange);
+ Exchange e = vHost.getExchangeRegistry().getExchange(exchange);
// if the exchange does not exist we raise a channel exception
if (e == null)
{
@@ -83,22 +83,18 @@
// The partially populated BasicDeliver frame plus the received route body
// is stored in the channel. Once the final body frame has been received
// it is routed to the exchange.
- AMQChannel channel = session.getChannel(evt.getChannelId());
+ AMQChannel channel = session.getChannel(channelId);
if (channel == null)
{
- throw body.getChannelNotFoundException(evt.getChannelId());
+ throw body.getChannelNotFoundException(channelId);
}
- if(body.routingKey != null)
- {
- body.routingKey = body.routingKey.intern();
- }
-
- MessagePublishInfo info = session.getRegistry().getProtocolVersionMethodConverter().convertToInfo(body);
+ MessagePublishInfo info = session.getMethodRegistry().getProtocolVersionMethodConverter().convertToInfo(body);
channel.setPublishFrame(info, session);
}
}
+
}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicQosHandler.java Sat Nov 24 13:14:14 2007
@@ -23,6 +23,8 @@
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.BasicQosBody;
import org.apache.qpid.framing.BasicQosOkBody;
+import org.apache.qpid.framing.MethodRegistry;
+import org.apache.qpid.framing.AMQMethodBody;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.state.AMQStateManager;
@@ -38,21 +40,21 @@
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicQosBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicQosBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
- AMQChannel channel = session.getChannel(evt.getChannelId());
+ AMQChannel channel = session.getChannel(channelId);
if (channel == null)
{
- throw evt.getMethod().getChannelNotFoundException(evt.getChannelId());
+ throw body.getChannelNotFoundException(channelId);
}
- channel.setPrefetchCount(evt.getMethod().prefetchCount);
- channel.setPrefetchSize(evt.getMethod().prefetchSize);
+ channel.setPrefetchCount(body.getPrefetchCount());
+ channel.setPrefetchSize(body.getPrefetchSize());
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- session.writeFrame(BasicQosOkBody.createAMQFrame(evt.getChannelId(), (byte) 8, (byte) 0));
+ MethodRegistry methodRegistry = session.getMethodRegistry();
+ AMQMethodBody responseBody = methodRegistry.createBasicQosOkBody();
+ session.writeFrame(responseBody.generateFrame(channelId));
+
}
}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -24,6 +24,9 @@
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.BasicRecoverBody;
import org.apache.qpid.framing.BasicRecoverOkBody;
+import org.apache.qpid.framing.ProtocolVersion;
+import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.amqp_8_0.MethodRegistry_8_0;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.protocol.AMQProtocolSession;
@@ -41,24 +44,30 @@
return _instance;
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicRecoverBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicRecoverBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
- _logger.debug("Recover received on protocol session " + session + " and channel " + evt.getChannelId());
- AMQChannel channel = session.getChannel(evt.getChannelId());
- BasicRecoverBody body = evt.getMethod();
+ _logger.debug("Recover received on protocol session " + session + " and channel " + channelId);
+ AMQChannel channel = session.getChannel(channelId);
+
if (channel == null)
{
- throw body.getChannelNotFoundException(evt.getChannelId());
+ throw body.getChannelNotFoundException(channelId);
}
- channel.resend(body.requeue);
+ channel.resend(body.getRequeue());
+
+ // Qpid 0-8 hacks a synchronous -ok onto recover.
+ // In Qpid 0-9 we create a separate sync-recover, sync-recover-ok pair to be "more" compliant
+ if(session.getProtocolVersion().equals(ProtocolVersion.v8_0))
+ {
+ MethodRegistry_8_0 methodRegistry = (MethodRegistry_8_0) session.getMethodRegistry();
+ AMQMethodBody recoverOk = methodRegistry.createBasicRecoverOkBody();
+ session.writeFrame(recoverOk.generateFrame(channelId));
+
+ }
- // AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
- // TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
- // Be aware of possible changes to parameter order as versions change.
- session.writeFrame(BasicRecoverOkBody.createAMQFrame(evt.getChannelId(), (byte) 8, (byte) 0));
}
}
Added: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverSyncMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverSyncMethodHandler.java?rev=597918&view=auto
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverSyncMethodHandler.java (added)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRecoverSyncMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -0,0 +1,54 @@
+package org.apache.qpid.server.handler;
+
+import org.apache.log4j.Logger;
+
+import org.apache.qpid.framing.BasicRecoverBody;
+import org.apache.qpid.framing.ProtocolVersion;
+import org.apache.qpid.framing.AMQMethodBody;
+import org.apache.qpid.framing.BasicRecoverSyncBody;
+import org.apache.qpid.framing.amqp_0_9.MethodRegistry_0_9;
+import org.apache.qpid.framing.amqp_8_0.MethodRegistry_8_0;
+import org.apache.qpid.server.state.StateAwareMethodListener;
+import org.apache.qpid.server.state.AMQStateManager;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.AMQException;
+
+public class BasicRecoverSyncMethodHandler implements StateAwareMethodListener<BasicRecoverSyncBody>
+{
+ private static final Logger _logger = Logger.getLogger(BasicRecoverSyncMethodHandler.class);
+
+ private static final BasicRecoverSyncMethodHandler _instance = new BasicRecoverSyncMethodHandler();
+
+ public static BasicRecoverSyncMethodHandler getInstance()
+ {
+ return _instance;
+ }
+
+ public void methodReceived(AMQStateManager stateManager, BasicRecoverSyncBody body, int channelId) throws AMQException
+ {
+ AMQProtocolSession session = stateManager.getProtocolSession();
+
+ _logger.debug("Recover received on protocol session " + session + " and channel " + channelId);
+ AMQChannel channel = session.getChannel(channelId);
+
+
+ if (channel == null)
+ {
+ throw body.getChannelNotFoundException(channelId);
+ }
+
+ channel.resend(body.getRequeue());
+
+ // Qpid 0-8 hacks a synchronous -ok onto recover.
+ // In Qpid 0-9 we create a separate sync-recover, sync-recover-ok pair to be "more" compliant
+ if(session.getProtocolVersion().equals(ProtocolVersion.v0_9))
+ {
+ MethodRegistry_0_9 methodRegistry = (MethodRegistry_0_9) session.getMethodRegistry();
+ AMQMethodBody recoverOk = methodRegistry.createBasicRecoverSyncOkBody();
+ session.writeFrame(recoverOk.generateFrame(channelId));
+
+ }
+
+ }
+}
Modified: incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java?rev=597918&r1=597917&r2=597918&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java (original)
+++ incubator/qpid/branches/M2.1/java/broker/src/main/java/org/apache/qpid/server/handler/BasicRejectMethodHandler.java Sat Nov 24 13:14:14 2007
@@ -45,11 +45,11 @@
{
}
- public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<BasicRejectBody> evt) throws AMQException
+ public void methodReceived(AMQStateManager stateManager, BasicRejectBody body, int channelId) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
- int channelId = evt.getChannelId();
+
// if (_logger.isDebugEnabled())
// {
@@ -63,18 +63,18 @@
if (channel == null)
{
- throw evt.getMethod().getChannelNotFoundException(channelId);
+ throw body.getChannelNotFoundException(channelId);
}
if (_logger.isDebugEnabled())
{
- _logger.debug("Rejecting:" + evt.getMethod().deliveryTag +
- ": Requeue:" + evt.getMethod().requeue +
+ _logger.debug("Rejecting:" + body.getDeliveryTag() +
+ ": Requeue:" + body.getRequeue() +
//": Resend:" + evt.getMethod().resend +
" on channel:" + channel.debugIdentity());
}
- long deliveryTag = evt.getMethod().deliveryTag;
+ long deliveryTag = body.getDeliveryTag();
UnacknowledgedMessage message = channel.getUnacknowledgedMessageMap().get(deliveryTag);
@@ -103,7 +103,7 @@
if (_logger.isTraceEnabled())
{
_logger.trace("Rejecting: DT:" + deliveryTag + "-" + message.message.debugIdentity() +
- ": Requeue:" + evt.getMethod().requeue +
+ ": Requeue:" + body.getRequeue() +
//": Resend:" + evt.getMethod().resend +
" on channel:" + channel.debugIdentity());
}
@@ -114,7 +114,7 @@
message.message.reject(message.message.getDeliveredSubscription(message.queue));
}
- if (evt.getMethod().requeue)
+ if (body.getRequeue())
{
channel.requeue(deliveryTag);
}