qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r609672 - in /incubator/qpid/trunk/qpid: cpp/managementgen/ cpp/managementgen/templates/ cpp/src/ cpp/src/qpid/broker/ cpp/src/qpid/management/ python/mgmt-cli/
Date Mon, 07 Jan 2008 16:28:08 GMT
Author: aconway
Date: Mon Jan  7 08:28:07 2008
New Revision: 609672

URL: http://svn.apache.org/viewvc?rev=609672&view=rev
Log:
Patch from https://issues.apache.org/jira/browse/QPID-722 by Ted Ross:

Two changes in this patch:

1) Management object IDs are now persistent for persistent (durable) objects. This is required
to provide continuity of historical management data across broker restarts. The format of
object IDs now indicates whether they are transient or persistent. The upper bit (bit 63)
is 0 for transient IDs and 1 for persistent IDs.

2) Changes have been made to the management code generator in preparation for allowing it
to be used by outside projects that wish to use the broker Plugin API for management access.

File-by-file notes:

M python/mgmt-cli/managementdata.py

    Enhanced user-friendly display of 64-bit object IDs to
    differentiate between persistent IDs and non-persistent IDs.

M cpp/src/Makefile.am

    Changed command line format for call to the management code
    generator.

M cpp/src/qpid/broker/Broker.cpp
M cpp/src/qpid/broker/Vhost.cpp
M cpp/src/qpid/broker/Queue.cpp

    Updated calls to ManagementAgent::addObject to use the new support
    for persistent IDs, ensuring that the management object IDs for
    persistent objects are themselves persistent.

M cpp/src/qpid/management/ManagementAgent.h
M cpp/src/qpid/management/ManagementAgent.cpp

    Added support (using defaulted arguments) to
    ManagementAgent::addObject for persistent object IDs

M cpp/managementgen/generate.py
M cpp/managementgen/schema.py
M cpp/managementgen/main.py

    Added the ability for templates to set variables to be used during
    code generation.

    Makefile fragment is now generated using a template rather than
    hard-code. This was done to help non-qpid code to use the code
    generator for management-via-qpid support.

M cpp/managementgen/templates/Args.h
M cpp/managementgen/templates/Class.cpp
M cpp/managementgen/templates/Class.h

    Use a generator variable to define the comment prefix.

A cpp/managementgen/templates/Makefile.mk

    New template for the qpid makefile fragment. 

Modified:
    incubator/qpid/trunk/qpid/cpp/managementgen/generate.py
    incubator/qpid/trunk/qpid/cpp/managementgen/main.py
    incubator/qpid/trunk/qpid/cpp/managementgen/schema.py
    incubator/qpid/trunk/qpid/cpp/managementgen/templates/Args.h
    incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.cpp
    incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.h
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Vhost.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.h
    incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py

Modified: incubator/qpid/trunk/qpid/cpp/managementgen/generate.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/managementgen/generate.py?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/managementgen/generate.py (original)
+++ incubator/qpid/trunk/qpid/cpp/managementgen/generate.py Mon Jan  7 08:28:07 2008
@@ -27,13 +27,18 @@
 import os.path
 import filecmp
 
-#=====================================================================================
-#
-#=====================================================================================
 class Template:
+  """
+  Expandable File Template - This class is instantiated each time a
+  template is to be expanded.  It is instantiated with the "filename"
+  which is the full path to the template file and the "handler" which
+  is an object that is responsible for storing variables (setVariable)
+  and expanding tags (substHandler).
+  """
   def __init__ (self, filename, handler):
     self.filename = filename
     self.handler  = handler
+    self.handler.initExpansion ()
 
   def expandLine (self, line, stream, object):
     cursor = 0
@@ -47,29 +52,78 @@
       stream.write (line[cursor:sub])
       cursor = subend + 2
 
-      tag    = line[sub:subend]
-      dotPos = tag.find (".")
-      if dotPos == -1:
-        raise ValueError ("Invalid tag: %s" % tag)
-      tagObject = tag[7:dotPos]
-      tagName   = tag[dotPos + 1:len (tag)]
-
-      self.handler (object, stream, tagObject, tagName)
+      tag      = line[sub:subend]
+      equalPos = tag.find ("=")
+      if equalPos == -1:
+        dotPos = tag.find (".")
+        if dotPos == -1:
+          raise ValueError ("Invalid tag: %s" % tag)
+        tagObject = tag[7:dotPos]
+        tagName   = tag[dotPos + 1:len (tag)]
+        self.handler.substHandler (object, stream, tagObject, tagName)
+      else:
+        tagKey = tag[7:equalPos]
+        tagVal = tag[equalPos + 1:len (tag)]
+        self.handler.setVariable (tagKey, tagVal)
 
   def expand (self, object):
     fd     = open (self.filename)
     stream = StringIO ()
-    
+
     for line in fd:
       self.expandLine (line, stream, object)
     fd.close ()
 
     return stream
 
-#=====================================================================================
-#
-#=====================================================================================
+
+class Makefile:
+  """ Object representing a makefile fragment """
+  def __init__ (self, filelists, templateFiles):
+    self.filelists     = filelists
+    self.templateFiles = templateFiles
+
+  def genGenSources (self, stream, variables):
+    mdir = variables["mgenDir"]
+    sdir = variables["specDir"]
+    stream.write (mdir + "/main.py \\\n")
+    stream.write ("    " + mdir + "/generate.py \\\n")
+    stream.write ("    " + mdir + "/schema.py \\\n")
+    stream.write ("    " + sdir + "/management-types.xml \\\n")
+    stream.write ("    " + sdir + "/management-schema.xml \\\n")
+    first = True
+    for template in self.templateFiles:
+      if first:
+        first = False
+        stream.write ("    ")
+      else:
+        stream.write (" \\\n    ")
+      stream.write (mdir + "/templates/" + template)
+
+  def genGenCppFiles (self, stream, variables):
+    first = True
+    for file in self.filelists["cpp"]:
+      if first:
+        first = False
+      else:
+        stream.write (" \\\n    ")
+      stream.write (file)
+
+  def genGenHFiles (self, stream, variables):
+    first = True
+    for file in self.filelists["h"]:
+      if first:
+        first = False
+      else:
+        stream.write (" \\\n    ")
+      stream.write (file)
+
+
 class Generator:
+  """
+  This class manages code generation using template files.  It is instantiated
+  once for an entire code generation session.
+  """
   def createPath (self, path):
     exists = True
     try:
@@ -99,10 +153,12 @@
     self.filelists["cpp"] = []
     self.filelists["mk"]  = []
     self.templateFiles    = []
+    self.variables        = {}
 
-  def genDisclaimer (self, stream):
-    stream.write ("// This source file was created by a code generator.\n")
-    stream.write ("// Please do not edit.")
+  def genDisclaimer (self, stream, variables):
+    prefix = variables["commentPrefix"]
+    stream.write (prefix + " This source file was created by a code generator.\n")
+    stream.write (prefix + " Please do not edit.")
 
   def fileExt (self, path):
     dot = path.rfind (".")
@@ -150,29 +206,35 @@
     path = self.dest + "Args" + method.getFullName () + extension
     return path
 
+  def initExpansion (self):
+    self.variables = {}
+
   def substHandler (self, object, stream, tagObject, tag):
     if tagObject == "Root":
       obj = "self"
     else:
       obj = "object"  # MUST be the same as the 2nd formal parameter
 
-    call = obj + ".gen" + tag + "(stream)"
+    call = obj + ".gen" + tag + "(stream, self.variables)"
     eval (call)
 
-  def makeClassFiles (self, templateFile, schema):
+  def setVariable (self, key, value):
+    self.variables[key] = value
+
+  def makeClassFiles (self, templateFile, schema, force=False):
     """ Generate an expanded template per schema class """
     classes  = schema.getClasses ()
-    template = Template (self.input + templateFile, self.substHandler)
+    template = Template (self.input + templateFile, self)
     self.templateFiles.append (templateFile)
     for _class in classes:
       target = self.targetClassFile (_class, templateFile)
       stream = template.expand (_class)
-      self.writeIfChanged (stream, target)
+      self.writeIfChanged (stream, target, force)
 
-  def makeMethodFiles (self, templateFile, schema):
+  def makeMethodFiles (self, templateFile, schema, force=False):
     """ Generate an expanded template per method-with-arguments """
     classes  = schema.getClasses ()
-    template = Template (self.input + templateFile, self.substHandler)
+    template = Template (self.input + templateFile, self)
     self.templateFiles.append (templateFile)
     for _class in classes:
       methods = _class.getMethods ()
@@ -180,50 +242,12 @@
         if method.getArgCount () > 0:
           target = self.targetMethodFile (method, templateFile)
           stream = template.expand (method)
-          self.writeIfChanged (stream, target)
-
-  def makeMakeFile (self, target):
-    stream = StringIO ()
-    stream.write ("# Generated makefile fragment.\n\n")
-    stream.write ("mgen_generator=$(mgen_dir)/main.py \\\n")
-    stream.write ("    $(mgen_dir)/generate.py \\\n")
-    stream.write ("    $(mgen_dir)/schema.py \\\n")
-    stream.write ("    $(top_srcdir)/../specs/management-types.xml \\\n")
-    stream.write ("    $(top_srcdir)/../specs/management-schema.xml \\\n    ")
-    first = 1
-    for template in self.templateFiles:
-      if first == 1:
-        first = 0
-      else:
-        stream.write (" \\\n    ")
-      stream.write ("$(mgen_dir)/templates/" + template)
-    
-    stream.write ("\n\nmgen_broker_cpp=")
-    first = 1
-    for file in self.filelists["cpp"]:
-      if first == 1:
-        first = 0
-      else:
-        stream.write (" \\\n    ")
-      stream.write (file.replace ("../src", "."))
-    stream.write ("\n\n")
-
-    stream.write ("# Header file install rules.\n")
-    stream.write ("qpid_managementdir = $(includedir)/qpid/management\n")
-    stream.write ("dist_qpid_management_HEADERS = ")
-    first = 1
-    for file in self.filelists["h"]:
-      if first == 1:
-        first = 0
-      else:
-        stream.write (" \\\n    ")
-      stream.write (file.replace ("../src", "."))
-    stream.write ("\n\n")
+          self.writeIfChanged (stream, target, force)
 
-    stream.write ("if GENERATE\n")
-    stream.write ("$(srcdir)/managementgen.mk: $(mgen_generator)\n")
-    stream.write ("\t$(mgen_cmd)\n")
-    stream.write ("\n$(mgen_generator):\n")
-    stream.write ("endif\n")
-
-    self.writeIfChanged (stream, target, force=True)
+  def makeSingleFile (self, templateFile, target, force=False):
+    """ Generate a single expanded template """
+    makefile = Makefile (self.filelists, self.templateFiles)
+    template = Template (self.input + templateFile, self)
+    self.templateFiles.append (templateFile)
+    stream = template.expand (makefile)
+    self.writeIfChanged (stream, target, force)

Modified: incubator/qpid/trunk/qpid/cpp/managementgen/main.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/managementgen/main.py?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/managementgen/main.py (original)
+++ incubator/qpid/trunk/qpid/cpp/managementgen/main.py Mon Jan  7 08:28:07 2008
@@ -24,32 +24,27 @@
 from optparse import OptionParser
 
 # Set command line options
-parser = OptionParser ()
-parser.add_option ("-o", "--outDir", dest="outdir", metavar="DIR",
-                   help="Destination directory for generated files")
-parser.add_option ("-t", "--typeFile", dest="typefile", metavar="FILE",
-                   help="Schema type document (XML file)")
-parser.add_option ("-s", "--schemaFile", dest="schemafile", metavar="FILE",
-                   help="Schema defintion document (XML file)")
-parser.add_option ("-i", "--templateDir", dest="templatedir", metavar="DIR",
-                   help="Directory where template files can be found")
+usage  = "usage: %prog [options] schema-document type-document template-directory out-directory"
+parser = OptionParser (usage=usage)
 parser.add_option ("-m", "--makefile", dest="makefile", metavar="FILE",
                    help="Makefile fragment")
 
 (opts, args) = parser.parse_args ()
 
-if opts.outdir      == None or \
-   opts.typefile    == None or \
-   opts.schemafile  == None or \
-   opts.templatedir == None:
-  parser.error ("Incorrect options, see --help for help")
+if len (args) < 4:
+  parser.error ("Too few arguments")
 
-gen    = Generator     (opts.outdir,   opts.templatedir)
-schema = PackageSchema (opts.typefile, opts.schemafile)
+schemafile  = args[0]
+typefile    = args[1]
+templatedir = args[2]
+outdir      = args[3]
+
+gen    = Generator     (outdir,   templatedir)
+schema = PackageSchema (typefile, schemafile)
 
 gen.makeClassFiles  ("Class.h",   schema)
 gen.makeClassFiles  ("Class.cpp", schema)
 gen.makeMethodFiles ("Args.h",    schema)
 
 if opts.makefile != None:
-  gen.makeMakeFile (opts.makefile)
+  gen.makeSingleFile ("Makefile.mk", opts.makefile, force=True)

Modified: incubator/qpid/trunk/qpid/cpp/managementgen/schema.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/managementgen/schema.py?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/managementgen/schema.py (original)
+++ incubator/qpid/trunk/qpid/cpp/managementgen/schema.py Mon Jan  7 08:28:07 2008
@@ -461,19 +461,19 @@
   # Code Generation Functions.  The names of these functions (minus the leading "gen")
   # match the substitution keywords in the template files.
   #===================================================================================
-  def genNameUpper (self, stream):
+  def genNameUpper (self, stream, variables):
     stream.write (self.getFullName ().upper ())
 
-  def genNameCamel (self, stream):
+  def genNameCamel (self, stream, variables):
     stream.write (self.getFullName ())
 
-  def genArguments (self, stream):
+  def genArguments (self, stream, variables):
     for arg in self.args:
       ctype  = arg.type.type.cpp
       dirTag = arg.dir.lower() + "_"
       stream.write ("    " + ctype + " " + dirTag + arg.getName () + ";\n")
 
-  def genSchema (self, stream):
+  def genSchema (self, stream, variables):
     stream.write ("    ft = FieldTable ();\n")
     stream.write ("    ft.setString (NAME,     \"" + self.name + "\");\n")
     stream.write ("    ft.setInt    (ARGCOUNT, " + str (len (self.args)) + ");\n")
@@ -571,25 +571,25 @@
   # Code Generation Functions.  The names of these functions (minus the leading "gen")
   # match the substitution keywords in the template files.
   #===================================================================================
-  def genAccessorMethods (self, stream):
+  def genAccessorMethods (self, stream, variables):
     for config in self.configElements:
       if config.access != "RC":
         config.genAccessor (stream)
     for inst in self.instElements:
       inst.genAccessor (stream)
 
-  def genConfigCount (self, stream):
+  def genConfigCount (self, stream, variables):
     stream.write ("%d" % len (self.configElements))
 
-  def genConfigDeclarations (self, stream):
+  def genConfigDeclarations (self, stream, variables):
     for element in self.configElements:
       element.genDeclaration (stream)
 
-  def genConfigElementSchema (self, stream):
+  def genConfigElementSchema (self, stream, variables):
     for config in self.configElements:
       config.genSchema (stream)
 
-  def genConstructorArgs (self, stream):
+  def genConstructorArgs (self, stream, variables):
     # Constructor args are config elements with read-create access
     result = ""
     first  = 1
@@ -601,12 +601,12 @@
           stream.write (", ")
         element.genFormalParam (stream)
 
-  def genConstructorInits (self, stream):
+  def genConstructorInits (self, stream, variables):
     for element in self.configElements:
       if element.isConstructorArg ():
         stream.write ("," + element.getName () + "(_" + element.getName () + ")")
 
-  def genDoMethodArgs (self, stream):
+  def genDoMethodArgs (self, stream, variables):
     methodCount = 0
     inArgCount  = 0
     for method in self.methods:
@@ -623,26 +623,26 @@
       else:
         stream.write ("string methodName, Buffer& inBuf, Buffer& outBuf")
 
-  def genEventCount (self, stream):
+  def genEventCount (self, stream, variables):
     stream.write ("%d" % len (self.events))
 
-  def genEventSchema (self, stream):
+  def genEventSchema (self, stream, variables):
     pass ###########################################################################
 
-  def genHiLoStatResets (self, stream):
+  def genHiLoStatResets (self, stream, variables):
     for inst in self.instElements:
       inst.genHiLoStatResets (stream)
 
-  def genInitializeElements (self, stream):
+  def genInitializeElements (self, stream, variables):
     for inst in self.instElements:
       inst.genInitialize (stream)
 
-  def genInstChangedStub (self, stream):
+  def genInstChangedStub (self, stream, variables):
     if len (self.instElements) == 0:
       stream.write ("    // Stub for getInstChanged.  There are no inst elements\n")
       stream.write ("    bool getInstChanged (void) { return false; }\n")
 
-  def genInstCount (self, stream):
+  def genInstCount (self, stream, variables):
     count = 0
     for inst in self.instElements:
       count = count + 1
@@ -650,24 +650,24 @@
         count = count + 2
     stream.write ("%d" % count)
 
-  def genInstDeclarations (self, stream):
+  def genInstDeclarations (self, stream, variables):
     for element in self.instElements:
       element.genDeclaration (stream)
 
-  def genInstElementSchema (self, stream):
+  def genInstElementSchema (self, stream, variables):
     for inst in self.instElements:
       inst.genSchema (stream)
 
-  def genMethodArgIncludes (self, stream):
+  def genMethodArgIncludes (self, stream, variables):
     for method in self.methods:
       if method.getArgCount () > 0:
         stream.write ("#include \"qpid/management/Args" +\
                       method.getFullName () + ".h\"\n")
 
-  def genMethodCount (self, stream):
+  def genMethodCount (self, stream, variables):
     stream.write ("%d" % len (self.methods))
 
-  def genMethodHandlers (self, stream):
+  def genMethodHandlers (self, stream, variables):
     for method in self.methods:
       stream.write ("\n    if (methodName == \"" + method.getName () + "\")\n    {\n")
       if method.getArgCount () == 0:
@@ -694,44 +694,44 @@
       stream.write ("        return;\n    }\n")
 
 
-  def genMethodIdDeclarations (self, stream):
+  def genMethodIdDeclarations (self, stream, variables):
     number = 1
     for method in self.methods:
       stream.write ("    static const uint32_t METHOD_" + method.getName().upper() +\
                     " = %d;\n" % number)
       number = number + 1
 
-  def genMethodSchema (self, stream):
+  def genMethodSchema (self, stream, variables):
     for method in self.methods:
-      method.genSchema (stream)
+      method.genSchema (stream, variables)
 
-  def genNameCap (self, stream):
+  def genNameCap (self, stream, variables):
     stream.write (self.name.capitalize ())
 
-  def genNameLower (self, stream):
+  def genNameLower (self, stream, variables):
     stream.write (self.name.lower ())
 
-  def genNameUpper (self, stream):
+  def genNameUpper (self, stream, variables):
     stream.write (self.name.upper ())
 
-  def genParentArg (self, stream):
+  def genParentArg (self, stream, variables):
     for config in self.configElements:
       if config.isParentRef == 1:
         stream.write (" _parent")
         return
 
-  def genParentRefAssignment (self, stream):
+  def genParentRefAssignment (self, stream, variables):
     for config in self.configElements:
       if config.isParentRef == 1:
         stream.write (config.getName () + \
                       " = _parent->GetManagementObject ()->getObjectId ();")
         return
 
-  def genWriteConfig (self, stream):
+  def genWriteConfig (self, stream, variables):
     for config in self.configElements:
       config.genWrite (stream);
 
-  def genWriteInst (self, stream):
+  def genWriteInst (self, stream, variables):
     for inst in self.instElements:
       inst.genWrite (stream);
 

Modified: incubator/qpid/trunk/qpid/cpp/managementgen/templates/Args.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/managementgen/templates/Args.h?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/managementgen/templates/Args.h (original)
+++ incubator/qpid/trunk/qpid/cpp/managementgen/templates/Args.h Mon Jan  7 08:28:07 2008
@@ -1,3 +1,4 @@
+/*MGEN:commentPrefix=//*/
 #ifndef _ARGS_/*MGEN:Method.NameUpper*/_
 #define _ARGS_/*MGEN:Method.NameUpper*/_
 

Modified: incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.cpp?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.cpp Mon Jan  7 08:28:07 2008
@@ -1,3 +1,4 @@
+/*MGEN:commentPrefix=//*/
 //
 // Licensed to the Apache Software Foundation (ASF) under one
 // or more contributor license agreements.  See the NOTICE file

Modified: incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.h?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.h (original)
+++ incubator/qpid/trunk/qpid/cpp/managementgen/templates/Class.h Mon Jan  7 08:28:07 2008
@@ -1,3 +1,4 @@
+/*MGEN:commentPrefix=//*/
 #ifndef _MANAGEMENT_/*MGEN:Class.NameUpper*/_
 #define _MANAGEMENT_/*MGEN:Class.NameUpper*/_
 

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Mon Jan  7 08:28:07 2008
@@ -22,10 +22,10 @@
 
 # Management generator.
 mgen_dir=$(top_srcdir)/managementgen
-mgen_cmd=$(mgen_dir)/main.py -o $(srcdir)/gen/qpid/management \
-	-t $(top_srcdir)/../specs/management-types.xml \
-	-s $(top_srcdir)/../specs/management-schema.xml \
-	-i $(mgen_dir)/templates -m $(srcdir)/managementgen.mk
+mgen_cmd=$(mgen_dir)/main.py -m $(srcdir)/managementgen.mk \
+	$(top_srcdir)/../specs/management-schema.xml \
+	$(top_srcdir)/../specs/management-types.xml \
+	$(mgen_dir)/templates $(srcdir)/gen/qpid/management
 
 endif				# GENERATE
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Mon Jan  7 08:28:07 2008
@@ -146,7 +146,7 @@
         mgmtObject->set_clusterName          ("");
         mgmtObject->set_version              (PACKAGE_VERSION);
         
-        managementAgent->addObject (mgmtObject);
+        managementAgent->addObject (mgmtObject, 1, 0);
 
         // Since there is currently no support for virtual hosts, a placeholder object
         // representing the implied single virtual host is added here to keep the

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp Mon Jan  7 08:28:07 2008
@@ -65,7 +65,11 @@
         {
             mgmtObject = management::Queue::shared_ptr
                 (new management::Queue (this, parent, _name, _store != 0, _autodelete, 0));
-            agent->addObject (mgmtObject);
+
+            // Add the object to the management agent only if this queue is not durable.
+            // If it's durable, we will add it later when the queue is assigned a persistenceId.
+            if (store == 0)
+                agent->addObject (mgmtObject);
         }
     }
 }
@@ -519,7 +523,12 @@
 
 void Queue::setPersistenceId(uint64_t _persistenceId) const
 { 
-    persistenceId = _persistenceId; 
+    if (mgmtObject != 0 && persistenceId == 0)
+    {
+        ManagementAgent::shared_ptr agent = ManagementAgent::getAgent ();
+        agent->addObject (mgmtObject, _persistenceId);
+    }
+    persistenceId = _persistenceId;
 }
 
 void Queue::encode(framing::Buffer& buffer) const 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Vhost.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Vhost.cpp?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Vhost.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Vhost.cpp Mon Jan  7 08:28:07 2008
@@ -33,7 +33,7 @@
         {
             mgmtObject = management::Vhost::shared_ptr
                 (new management::Vhost (this, parentBroker, "/"));
-            agent->addObject (mgmtObject);
+            agent->addObject (mgmtObject, 2, 0);
         }
     }
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.cpp Mon Jan  7 08:28:07
2008
@@ -73,10 +73,17 @@
     dExchange = _dexchange;
 }
 
-void ManagementAgent::addObject (ManagementObject::shared_ptr object)
+void ManagementAgent::addObject (ManagementObject::shared_ptr object,
+                                 uint64_t                     persistenceId,
+                                 uint64_t                     idOffset)
 {
     RWlock::ScopedWlock writeLock (userLock);
-    uint64_t objectId = nextObjectId++;
+    uint64_t objectId;
+
+    if (persistenceId == 0)
+        objectId = nextObjectId++;
+    else
+        objectId = 0x8000000000000000ULL | (persistenceId + idOffset);
 
     object->setObjectId (objectId);
     managementObjects[objectId] = object;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.h?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementAgent.h Mon Jan  7 08:28:07
2008
@@ -51,7 +51,9 @@
     void setInterval     (uint16_t _interval) { interval = _interval; }
     void setExchange     (broker::Exchange::shared_ptr mgmtExchange,
                           broker::Exchange::shared_ptr directExchange);
-    void addObject       (ManagementObject::shared_ptr object);
+    void addObject       (ManagementObject::shared_ptr object,
+                          uint64_t                     persistenceId = 0,
+                          uint64_t                     idOffset      = 10);
     void clientAdded     (void);
     void dispatchCommand (broker::Deliverable&             msg,
                           const std::string&               routingKey,

Modified: incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py?rev=609672&r1=609671&r2=609672&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py (original)
+++ incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py Mon Jan  7 08:28:07 2008
@@ -44,6 +44,21 @@
   #    element       :== (<element-name>, <element-value>)
   #
 
+  def registerObjId (self, objId):
+    if self.baseId == 0:
+      if objId & 0x8000000000000000L == 0:
+        self.baseId = objId - 1000
+
+  def displayObjId (self, objId):
+    if objId & 0x8000000000000000L == 0:
+      return objId - self.baseId
+    return (objId & 0x7fffffffffffffffL) + 5000
+
+  def rawObjId (self, displayId):
+    if displayId < 5000:
+      return displayId + self.baseId
+    return displayId - 5000 + 0x8000000000000000L
+
   def dataHandler (self, context, className, list, timestamps):
     """ Callback for configuration and instrumentation data updates """
     self.lock.acquire ()
@@ -53,10 +68,9 @@
       if className not in self.tables:
         self.tables[className] = {}
 
-      # Calculate a base-id so displayed IDs are reasonable 4-digit numbers
+      # Register the ID so a more friendly presentation can be displayed
       id = long (list[0][1])
-      if self.baseId == 0:
-        self.baseId = id - 1000
+      self.registerObjId (id)
 
       # If this object hasn't been seen before, create a new object record with
       # the timestamps and empty lists for configuration and instrumentation data.
@@ -129,7 +143,7 @@
   def refName (self, oid):
     if oid == 0:
       return "NULL"
-    return str (oid - self.baseId)
+    return str (self.displayObjId (oid))
 
   def valueDisplay (self, className, key, value):
     for kind in range (2):
@@ -244,12 +258,12 @@
     list = []
     if tokens[0] == "all":
       for id in self.tables[className]:
-        list.append (id - self.baseId)
+        list.append (self.displayObjId (id))
 
     elif tokens[0] == "active":
       for id in self.tables[className]:
         if self.tables[className][id][0][2] == 0:
-          list.append (id - self.baseId)
+          list.append (self.displayObjId (id))
 
     else:
       for token in tokens:
@@ -257,7 +271,7 @@
           if token.find ("-") != -1:
             ids = token.split("-", 2)
             for id in range (int (ids[0]), int (ids[1]) + 1):
-              if self.getClassForId (long (id) + self.baseId) == className:
+              if self.getClassForId (self.rawObjId (long (id))) == className:
                 list.append (id)
           else:
             list.append (token)
@@ -329,7 +343,7 @@
         else:
           rootId = int (tokens[0])
 
-        className = self.getClassForId (rootId + self.baseId)
+        className = self.getClassForId (self.rawObjId (rootId))
         remaining = tokens
         if className == None:
           print "Id not known: %d" % int (tokens[0])
@@ -348,8 +362,8 @@
 
       ids = []
       for id in userIds:
-        if self.getClassForId (long (id) + self.baseId) == className:
-          ids.append (long (id) + self.baseId)
+        if self.getClassForId (self.rawObjId (long (id))) == className:
+          ids.append (self.rawObjId (long (id)))
 
       rows = []
       timestamp = None
@@ -481,7 +495,7 @@
     self.lock.acquire ()
     methodOk = True
     try:
-      className = self.getClassForId (userOid + self.baseId)
+      className = self.getClassForId (self.rawObjId (userOid))
       if className == None:
         raise ValueError ()
 
@@ -505,7 +519,7 @@
     self.lock.release ()
     if methodOk:
 #      try:
-        self.broker.method (self.methodSeq, userOid + self.baseId, className,
+        self.broker.method (self.methodSeq, self.rawObjId (userOid), className,
                             methodName, namedArgs)
 #      except ValueError, e:
 #        print "Error invoking method:", e



Mime
View raw message