summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFraser Adams <fadams@apache.org>2013-04-08 15:19:04 +0000
committerFraser Adams <fadams@apache.org>2013-04-08 15:19:04 +0000
commit797fcaf14ca1bfeb5778cbe526b3110f256862f2 (patch)
tree052572627ac304f44bdf07458120fedf4e195ba4
parent7f1f7f7a01cfcbb892285dc3a7d9372d1fb1ff43 (diff)
downloadqpid-python-797fcaf14ca1bfeb5778cbe526b3110f256862f2.tar.gz
QPID-3675: Java QMF2 API, REST API, QMF GUI and Java Broker QMF Management Plugin added to <qpid>/tools/src/java
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1465662 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/tools/src/java/README-Java-Broker.txt350
-rw-r--r--qpid/tools/src/java/README.txt73
-rwxr-xr-xqpid/tools/src/java/bin/ConnectionAudit.sh35
-rwxr-xr-xqpid/tools/src/java/bin/ConnectionLogger.sh35
-rwxr-xr-xqpid/tools/src/java/bin/QpidConfig.sh35
-rwxr-xr-xqpid/tools/src/java/bin/QpidCtrl.sh35
-rwxr-xr-xqpid/tools/src/java/bin/QpidPrintEvents.sh35
-rwxr-xr-xqpid/tools/src/java/bin/QpidQueueStats.sh35
-rwxr-xr-xqpid/tools/src/java/bin/QpidRestAPI.sh35
-rwxr-xr-xqpid/tools/src/java/bin/QueueFuse.sh35
-rw-r--r--qpid/tools/src/java/bin/log4j.xml50
-rw-r--r--qpid/tools/src/java/bin/qpid-web/authentication/account.properties3
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/apple-touch-icon.pngbin0 -> 25357 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/favicon.icobin0 -> 4286 bytes
-rwxr-xr-xqpid/tools/src/java/bin/qpid-web/web/index.html38
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/css/LICENCE29
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie6.css302
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie7.css193
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie8.css140
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie9.css24
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet.css973
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/action.pngbin0 -> 1253 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/add.pngbin0 -> 2042 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/bin.pngbin0 -> 889 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-button-sprite.pngbin0 -> 2102 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-chevron.pngbin0 -> 1615 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/blueball.pngbin0 -> 851 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/button-sprite.pngbin0 -> 2405 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron-active.pngbin0 -> 308 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron.pngbin0 -> 259 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/delete.pngbin0 -> 5361 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/flag.pngbin0 -> 1068 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/home.pngbin0 -> 727 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/active-gradient.pngbin0 -> 174 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-button-sprite.gifbin0 -> 2214 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-chevron.gifbin0 -> 763 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/button-sprite.gifbin0 -> 2287 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron-active.gifbin0 -> 166 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron.gifbin0 -> 97 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/header-gradient.pngbin0 -> 204 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radial-gradient.pngbin0 -> 865 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-10px-sprite.pngbin0 -> 750 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-5px-sprite.pngbin0 -> 212 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/red6.pngbin0 -> 187 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/smoked.pngbin0 -> 187 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick-active.gifbin0 -> 101 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick.gifbin0 -> 167 bytes
-rwxr-xr-xqpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.gifbin0 -> 49 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.pngbin0 -> 178 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/mask.pngbin0 -> 941 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/move.pngbin0 -> 1061 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/on_off.pngbin0 -> 3398 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick-active.pngbin0 -> 380 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick.pngbin0 -> 559 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-off.pngbin0 -> 181 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on-border.pngbin0 -> 452 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on.pngbin0 -> 211 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/images/write.pngbin0 -> 1200 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/LICENCE72
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/iscroll.js1117
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/itablet.js1492
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/jquery.js4
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/LICENCE26
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/index.css43
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/qmf.css124
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/brokers.pngbin0 -> 1794 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/connections.pngbin0 -> 1931 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/events.pngbin0 -> 2419 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/exchanges.pngbin0 -> 2428 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/gradient.pngbin0 -> 89 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/links.pngbin0 -> 2499 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/loading.gifbin0 -> 3208 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/qpid-logo.pngbin0 -> 32948 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/queues.pngbin0 -> 2293 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/route-topology.pngbin0 -> 2014 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/settings.pngbin0 -> 2687 bytes
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/LICENCE63
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/excanvas.js1416
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/qmf-ui.js3526
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/LICENCE23
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/qpid.js745
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/ui/config.js15
-rw-r--r--qpid/tools/src/java/bin/qpid-web/web/ui/qmf.html1292
-rw-r--r--qpid/tools/src/java/bin/whitelist.xml33
-rw-r--r--qpid/tools/src/java/build.xml241
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Agent.java1461
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/AgentExternal.java259
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallParams.java123
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallWorkItem.java64
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QmfAgentData.java364
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QueryWorkItem.java85
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeParams.java78
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeRequestWorkItem.java66
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribableAgent.java70
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribeRequestWorkItem.java69
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Subscription.java280
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscriptionParams.java102
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/UnsubscribeRequestWorkItem.java65
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfData.pngbin0 -> 3876 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfEventListenerModel.pngbin0 -> 5412 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfQuery.pngbin0 -> 8444 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Schema.pngbin0 -> 4911 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Subscriptions.pngbin0 -> 3365 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/WorkQueueEventModel.pngbin0 -> 7521 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/AMQPMessage.java309
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BlockingNotifier.java65
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanEquals.java79
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExists.java72
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExpression.java221
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanFalse.java60
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterEqual.java89
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterThan.java89
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessEqual.java89
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessThan.java89
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanNotEquals.java79
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanRegexMatch.java95
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanTrue.java60
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Expression.java77
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Handle.java107
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalAnd.java62
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalExpression.java64
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalNot.java62
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalOr.java62
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Notifier.java67
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NotifierWrapper.java57
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NullQmfEventListener.java43
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/ObjectId.java159
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfCallback.java33
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java443
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java84
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java224
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java51
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java42
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java83
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java343
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java36
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java39
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java135
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java202
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java266
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java275
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaObjectClass.java378
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaProperty.java364
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkItem.java399
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkQueue.java106
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Console.pngbin0 -> 6234 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfData.pngbin0 -> 3876 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfEventListenerModel.pngbin0 -> 5412 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfQuery.pngbin0 -> 8444 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Schema.pngbin0 -> 4911 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Subscriptions.pngbin0 -> 5382 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkItem.pngbin0 -> 9007 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkQueueEventModel.pngbin0 -> 7521 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Agent.java482
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAccessWorkItem.java80
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAddedWorkItem.java49
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentDeletedWorkItem.java50
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentHeartbeatWorkItem.java48
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentProxy.java85
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentRestartedWorkItem.java46
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Console.java2237
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/EventReceivedWorkItem.java63
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResponseWorkItem.java65
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResult.java151
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/ObjectUpdateWorkItem.java65
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/QmfConsoleData.java277
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeIndication.java66
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeParams.java130
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeResponseWorkItem.java80
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionIndicationWorkItem.java62
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionManager.java255
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Console.pngbin0 -> 6234 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/QmfEventListenerModel.pngbin0 -> 5412 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Subscriptions.pngbin0 -> 2789 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/WorkQueueEventModel.pngbin0 -> 7521 bytes
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionAudit.java474
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionLogger.java383
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidConfig.java1564
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidCtrl.java358
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidPrintEvents.java210
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidQueueStats.java374
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QueueFuse.java364
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/ConnectionHelper.java862
-rw-r--r--qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/GetOpt.java208
-rw-r--r--qpid/tools/src/java/src/patch/java/AMQMessageDelegate_0_10.java958
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java592
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementFactory.java79
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementPlugin.java300
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Binding.java203
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Broker.java678
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Connection.java203
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Exchange.java252
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Queue.java287
-rw-r--r--qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Subscription.java207
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionProxy.java287
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionStore.java138
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/FileServer.java369
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/HttpTransaction.java165
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSON.java265
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSONMapParser.java402
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidRestAPI.java206
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidServer.java654
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/Server.java95
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Authenticator.java151
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Delegator.java89
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/HttpExchangeTransaction.java311
-rw-r--r--qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/servlet/TODO4
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java558
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java224
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java298
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java308
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java174
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java155
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BrokerSubscriptionTestConsole.java262
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/InvokeMethodTest.java112
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/PartialGetObjectsTest.java177
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/SchemaTest.java126
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test1.java140
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test2.java121
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test3.java137
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test4.java339
-rw-r--r--qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/URLTest.java82
-rwxr-xr-xqpid/tools/src/java/test/bin/AgentExternalTest.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/AgentSubscriptionTestConsole.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/AgentTest.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/AgentTestConsole.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/BigPayloadAgentTest.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/BigPayloadAgentTestConsole.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/BrokerSubscriptionTestConsole.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/InvokeMethodTest.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/PartialGetObjectsTest.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/SchemaTest.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/Test1.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/Test2.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/Test3.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/Test4.sh30
-rwxr-xr-xqpid/tools/src/java/test/bin/URLTest.sh30
-rw-r--r--qpid/tools/src/java/test/bin/log4j.xml50
238 files changed, 41128 insertions, 0 deletions
diff --git a/qpid/tools/src/java/README-Java-Broker.txt b/qpid/tools/src/java/README-Java-Broker.txt
new file mode 100644
index 0000000000..fccf19a099
--- /dev/null
+++ b/qpid/tools/src/java/README-Java-Broker.txt
@@ -0,0 +1,350 @@
+
+The Qpid Java Broker by default uses either JMX or an HTTP Management GUI & REST API, however by building
+a QMF2 Agent as a Java Broker plugin it's possible to provide better synergy between the C++ and Java Brokers
+and allow the Java Broker to be controlled by the Qpid Command Line tools and also via the QMF2 REST API
+and GUI thus providing a unified view across a mixture of C++ and Java Brokers.
+
+
+To build and install the Java Broker QMF2 plugin do:
+
+ant all
+
+***********************************************************************************************************
+* Note that the QmfManagementPlugin requires a version of the Java Broker >= 0.22 *
+* *
+* The initial version of QmfManagementPlugin released to https://issues.apache.org/jira/browse/QPID-3675 *
+* uses the ManagementPlugin and ManagementFactory interfaces which were introduced in Qpid 0.20 but then *
+* dropped in Qpid 0.22 so the version linked to the Jira is the only version that will work with the 0.20 *
+* Java Broker. *
+* *
+* As of Qpid 0.22 the Java Broker Plugin and Configuration APIs have changed. The Plugin API implements *
+* org.apache.qpid.server.model.Plugin extending org.apache.qpid.server.model.adapter.AbstractPluginAdapter*
+* and uses org.apache.qpid.server.plugin.PluginFactory to create the Plugin instance. *
+* *
+* The Plugin uses the org.apache.qpid.server.model.* classes and maps them to QmfData. *
+* *
+* The intention is to track changes on Qpid Trunk, but the Plugin API is still under a bit of flux *
+***********************************************************************************************************
+
+N.B. this requires that the Qpid jars (preferably qpid-all.jar) are on your CLASSPATH and that the
+QPID_HOME environment variable is set to point to <qpid>/java/build (QPID_HOME is needed by the Java
+broker anyway).
+
+The ant all target compiles the Java Broker QMF2 plugin and copies the qpid-broker-plugins-management-qmf2.jar
+and qmf2.jar to $QPID_HOME/lib/plugins creating the plugins directory if it doesn't already exist. That
+directory is one read by the qpid-server broker startup script and placed on the broker's CLASSPATH.
+
+
+
+************************************************* Config **************************************************
+
+As of Qpid 0.22 the way of configuring the Java Broker has moved to an initial config.json file in
+$QPID_WORK and updates via the Management Plugins. It is IMPORTANT to ensure that the following:
+
+{
+ "name" : "qmf2Management",
+ "pluginType" : "MANAGEMENT-QMF2",
+ "connectionURL" : "amqp://guest:guest@/?brokerlist='tcp://0.0.0.0:5672'"
+ }
+
+is added to the "plugins" list of $QPID_WORK/config.json or the Plugin will not start. There is also an "id"
+property but if this is omitted it will get automatically created the first time the Plugin starts, which
+is probably more useful that trying to make a UUID up.
+
+The "connectionURL" property is particularly important. The Plugin connects to AMQP via the JMS Client so
+"connectionURL" represents a valid Java ConnectionURL to the Broker so the username/password and any other
+ConnectionURL configuration needs to be valid as for any other AMQP Connection to the Broker.
+
+
+If the QMF GUI is to be used then either the -p option of QpidRestAPI.sh should be used to set the REST Server's
+HTTP port to something other than 8080 or the "ports" list of $QPID_WORK/config.json should be modified from e.g.
+{
+ "id" : "1f2c4c7a-f33a-316b-b0e9-c02fab74469d",
+ "name" : "8080-HTTP",
+ "port" : 8080,
+ "protocols" : [ "HTTP" ]
+ }
+
+to
+
+{
+ "id" : "1f2c4c7a-f33a-316b-b0e9-c02fab74469d",
+ "name" : "9090-HTTP",
+ "port" : 9090,
+ "protocols" : [ "HTTP" ]
+ }
+
+So that the HTTP ports don't conflict.
+
+
+In the top-level Broker config the "defaultVirtualHost" *MUST* be set to the name of the default Virtual Host
+if this property is not set or is set to a name that doesn't match the name of one of the Virtual Hosts
+then the Plugin will not start correctly.
+
+
+******************************************** Troubleshooting **********************************************
+
+If all has gone well you should see
+
+[Broker] MNG-1001 : QMF2 Management Startup
+[Broker] MNG-1004 : QMF2 Management Ready
+
+in the Broker log messages when you run qpid-server, if you don't see these then there is likely to be a problem.
+
+1. Check the directory $QPID_HOME/lib/plugins
+That should contain qmf2.jar and qpid-broker-plugins-management-qmf2.jar if it doesn't then the Plugin hasn't been
+built or deployed try doing
+
+ant all
+
+again.
+
+2. If the jars mentioned above are present and correct in the plugins directory the most likely cause of failure
+is incorrect configuration - see the Config section above, in particular the "plugins" list and "defaultVirtualHost".
+
+
+
+******************************* Java Broker Management Plugin - mini HOWTO ********************************
+
+The procedure for writing Plugins for the Java Broker isn't documented yet, so the following mini HOWTO
+describes what I did. It may not be the *right* way but it seems to result in a Plugin that starts with the broker.
+
+1. Create a PluginFactory
+
+Management plugins are instantiated by Factory classes that implement the interface
+org.apache.qpid.server.plugin.PluginFactory e.g.
+
+
+package org.apache.qpid.server.qmf2;
+
+// Misc Imports
+import java.util.Map;
+import java.util.UUID;
+
+// Java Broker Management Imports
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
+
+public class QmfManagementFactory implements PluginFactory
+{
+ /**
+ * This factory method creates an instance of QmfManagementPlugin called via the QpidServiceLoader.
+ * @param id the UUID of the Plugin.
+ * @param attributes a Map containing configuration information for the Plugin.
+ * @param broker the root Broker Management Object from which the other Management Objects may be obtained.
+ * @return the QmfManagementPlugin instance which creates a QMF2 Agent able to interrogate the broker Management
+ * Objects and return their properties as QmfData.
+ */
+ @Override
+ public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker)
+ {
+ if (QmfManagementPlugin.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE)))
+ {
+ return new QmfManagementPlugin(id, broker, attributes);
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
+
+
+2. Create a Plugin
+
+Plugins implement the interface org.apache.qpid.server.model.Plugin which seems to be done by extending
+org.apache.qpid.server.model.adapter.AbstractPluginAdapter. The main APIs are to override the setState()
+and getName() methods and to implement a static initialiser to populate ConfiguredObject ATTRIBUTES.
+
+
+package org.apache.qpid.server.qmf2;
+
+// Misc Imports
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+// Java Broker Management Imports
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AbstractPluginAdapter;
+
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.util.MapValueConverter;
+
+public class QmfManagementPlugin extends AbstractPluginAdapter
+{
+ private static final String OPERATIONAL_LOGGING_NAME = "QMF2";
+
+ /************* Static initialiser used to implement org.apache.qpid.server.model.Plugin *************/
+
+ public static final String PLUGIN_TYPE = "MANAGEMENT-QMF2";
+
+ // attributes
+ public static final String NAME = "name";
+ public static final String CONNECTION_URL = "connectionURL";
+
+ // default values
+ public static final String DEFAULT_NAME = "qmf2Management";
+ public static final String DEFAULT_CONNECTION_URL = "amqp://guest:guest@/?brokerlist='tcp://0.0.0.0:5672'";
+
+ @SuppressWarnings("serial")
+ private static final Collection<String> AVAILABLE_ATTRIBUTES = Collections.unmodifiableCollection(
+ new HashSet<String>(Plugin.AVAILABLE_ATTRIBUTES){{
+ add(NAME);
+ add(CONNECTION_URL);
+ add(PluginFactory.PLUGIN_TYPE);
+ }});
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Object> DEFAULTS = new HashMap<String, Object>(){{
+ put(NAME, DEFAULT_NAME);
+ put(CONNECTION_URL, DEFAULT_CONNECTION_URL);
+ put(PluginFactory.PLUGIN_TYPE, PLUGIN_TYPE);
+ }};
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Type> ATTRIBUTE_TYPES = new HashMap<String, Type>(){{
+ put(NAME, String.class);
+ put(CONNECTION_URL, String.class);
+ put(PluginFactory.PLUGIN_TYPE, String.class);
+ }};
+
+ /************************************ End of Static initialiser *************************************/
+
+ /**
+ * Constructor, called at broker startup by QmfManagementFactory.createInstance().
+ * @param id the UUID of the Plugin.
+ * @param attributes a Map containing configuration information for the Plugin.
+ * @param broker the root Broker Management Object from which the other Management Objects may be obtained.
+ */
+ public QmfManagementPlugin(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), broker.getTaskExecutor());
+ addParent(Broker.class, broker);
+System.out.println("************ Constructing QmfManagementPlugin");
+ }
+
+ /**
+ * Set the state of the Plugin, I believe that this is called from the BrokerAdapter object when it
+ * has its own state set to State.ACTIVE or State.STOPPED.
+ * When State.ACTIVE is set this calls the start() method to startup the Plugin, when State.STOPPED
+ * is set this calls the stop() method to shutdown the Plugin.
+ * @param currentState the current state of the Plugin (ignored).
+ * @param desiredState the desired state of the Plugin (either State.ACTIVE or State.STOPPED).
+ * @return true if a valid state has been set, otherwise false.
+ */
+ @Override // From org.apache.qpid.server.model.adapter.AbstractAdapter
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ start();
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ stop();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ private void start()
+ {
+ // Log "QMF2 Management Startup" message.
+ CurrentActor.get().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
+
+ // Log QMF2 Management Ready message.
+ CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
+ }
+
+ private void stop()
+ {
+ // Log "QMF2 Management Stopped" message (may not get displayed).
+ CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
+ }
+
+ /**
+ * Get the name of this Plugin.
+ * @return the Plugin name (default is "qmf2Management").
+ */
+ @Override // From org.apache.qpid.server.model.ConfiguredObject
+ public String getName()
+ {
+ return (String)getAttribute(NAME);
+ }
+
+ /**
+ * Accessor to retrieve the names of the available attributes. It is important to provide this overridden
+ * method because the Constructor uses this information when populating the underlying AbstractPlugin
+ * information. If we don't provide this override method getAttribute(name) will return the default values.
+ * @return the names of the available Plugin config attributes as a Collection.
+ */
+ @Override // From org.apache.qpid.server.model.adapter.AbstractPluginAdapter
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+}
+
+3. Populate the META-INF
+
+Qpid Java broker Plugins seem to use a facade over java.util.ServiceLoader called
+org.apache.qpid.server.plugin.QpidServiceLoader. In order to use a ServiceLoader the jar containing the Plugin
+needs to contain a file:
+META-INF/services/org.apache.qpid.server.plugin.PluginFactory
+
+which contains the fully qualified class name of the class implementing PluginFactory e.g.
+
+org.apache.qpid.server.qmf2.QmfManagementFactory
+
+
+The most convenient way to achieve this is to include a ServiceProvider block in the jar ant task e.g.
+
+ <jar destfile="build/lib/qpid-broker-plugins-management-qmf2.jar"
+ basedir="build/scratch/qpid-broker-plugins-management-qmf2">
+
+ <service type="org.apache.qpid.server.plugin.PluginFactory"
+ provider="org.apache.qpid.server.qmf2.QmfManagementFactory"/>
+ </jar>
+
+
+4. Build the jar using your favourite method.
+
+5. Deploy the jar to $QPID_HOME/lib/plugins
+
+6. Ensure the config.json file in $QPID_WORK contains:
+{
+ "name" : "qmf2Management",
+ "pluginType" : "MANAGEMENT-QMF2",
+ "connectionURL" : "amqp://guest:guest@/?brokerlist='tcp://0.0.0.0:5672'"
+ }
+
+(or whatever the name/pluginType/etc. of the actual Plugin is)
+in the "plugins" list (the id property will be added automatically when the Broker starts)
+
+7. Start up the Java Broker via qpid-server
+
+
+If all has gone well the Plugin should start up. Clearly you'll probably want to add something to the Plugin so
+that it actually does something vaguely useful :-)
+
+
+
+
diff --git a/qpid/tools/src/java/README.txt b/qpid/tools/src/java/README.txt
new file mode 100644
index 0000000000..3cd57605b4
--- /dev/null
+++ b/qpid/tools/src/java/README.txt
@@ -0,0 +1,73 @@
+
+This is a Java JMS implementation of the QMF2 API specified at
+https://cwiki.apache.org/qpid/qmfv2-api-proposal.html
+
+The Qpid Java jar needs to be on your classpath - I tend to use qpid-all.jar but client only jars should be OK too.
+
+QMF2 support is now available for the Qpid Java Broker see README-Java-Broker.txt for details.
+
+
+
+*********************************************** Important!! ***********************************************
+* If your version of Qpid is older than 0.12 the QMF2 API won't work unless your setup is as follows: *
+*********************************************** Important!! ***********************************************
+
+For those who are running with Qpid 0.12 or above the patch described below isn't necessary.
+The default "api" ant target in build.xml builds everything except the patch, which is the preferred
+approach for later Qpid versions, though using the patched version of the older AMQMessageDelegate_0_10.java
+still works with Qpid 0.12 (but not with later Qpid versions).
+
+
+To be clear, if you are using Qpid Java jars 0.12 or above you do not need to use the patch described below
+even if you are talking to an earlier broker, however do note that if you are talking to a broker < Qpid 0.10
+you need to set "--mgmt-qmf2 yes" when you start up qpidd if you want to get QMF2 Events and heartbeats pushed.
+This is particularly important to note if you are using the Qpid GUI, as in default mode its updates are
+triggered by the QMF2 heartbeats. If "--mgmt-qmf2 yes" isn't set on a 0.8 broker you'll see "Broker Disconnected"
+flash briefly every 30 seconds or so as timeouts occur. Creating a QMF Console Connecton in the GUI with
+"Disable Events" selected uses a timed poll rather than a heartbeat so it may be better to do that for cases
+where access to the broker configuration is not available.
+
+***********************************************************************************************************
+
+Note 1: This uses QMF2 so requires that the "--mgmt-qmf2 yes" option is applied to the broker (this is
+ the default from Qpid 0.10 onwards)
+Note 2: In order to use QMF2 the app-id field needs to be set. There appears to be no way to set the AMQP
+ 0-10 specific app-id field on a message which the broker's QMFv2 implementation currently requires.
+
+Gordon Sim has put together a patch for org.apache.qpid.client.message.AMQMessageDelegate_0_10
+Found in client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java
+
+public void setStringProperty(String propertyName, String value) throws JMSException
+{
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, value);
+
+ if ("x-amqp-0-10.app-id".equals(propertyName))
+ {
+ _messageProps.setAppId(value.getBytes());
+ }
+}
+
+The jira "https://issues.apache.org/jira/browse/QPID-3302." covers this.
+
+
+This has been fixed in Qpid 0.12, but I've included a patched version of AMQMessageDelegate_0_10.java
+in the build directory so that people using earlier versions can get up and running (the QMF2 library
+was initially developed using Qpid 0.10).
+
+
+The "api-patched" ant target in build.xml creates a qpid-client-patch.jar in addition to the qmf2.jar and qmf2test.jar
+
+It is assumed that the qpid-clientxxx.jar is already on your CLASSPATH so one would do:
+
+CLASSPATH=../../build/lib/qpid-client-patch.jar:$CLASSPATH:../../build/lib/qmf2.jar:../../build/lib/qmf2test.jar
+
+to put the patched AMQMessageDelegate_0_10 ahead of the unpatched one. This is already done for the scripts that
+call the various test and tool classes.
+
+
+
+
+
+
diff --git a/qpid/tools/src/java/bin/ConnectionAudit.sh b/qpid/tools/src/java/bin/ConnectionAudit.sh
new file mode 100755
index 0000000000..303c61cbc6
--- /dev/null
+++ b/qpid/tools/src/java/bin/ConnectionAudit.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.qmf2.tools.ConnectionAudit "$@"
diff --git a/qpid/tools/src/java/bin/ConnectionLogger.sh b/qpid/tools/src/java/bin/ConnectionLogger.sh
new file mode 100755
index 0000000000..77ae9ee334
--- /dev/null
+++ b/qpid/tools/src/java/bin/ConnectionLogger.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.qmf2.tools.ConnectionLogger "$@"
diff --git a/qpid/tools/src/java/bin/QpidConfig.sh b/qpid/tools/src/java/bin/QpidConfig.sh
new file mode 100755
index 0000000000..9f191d3d3d
--- /dev/null
+++ b/qpid/tools/src/java/bin/QpidConfig.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.qmf2.tools.QpidConfig "$@"
diff --git a/qpid/tools/src/java/bin/QpidCtrl.sh b/qpid/tools/src/java/bin/QpidCtrl.sh
new file mode 100755
index 0000000000..8b10338c7b
--- /dev/null
+++ b/qpid/tools/src/java/bin/QpidCtrl.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.qmf2.tools.QpidCtrl "$@"
diff --git a/qpid/tools/src/java/bin/QpidPrintEvents.sh b/qpid/tools/src/java/bin/QpidPrintEvents.sh
new file mode 100755
index 0000000000..1e8d03093b
--- /dev/null
+++ b/qpid/tools/src/java/bin/QpidPrintEvents.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.qmf2.tools.QpidPrintEvents "$@"
diff --git a/qpid/tools/src/java/bin/QpidQueueStats.sh b/qpid/tools/src/java/bin/QpidQueueStats.sh
new file mode 100755
index 0000000000..7685562e3b
--- /dev/null
+++ b/qpid/tools/src/java/bin/QpidQueueStats.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.qmf2.tools.QpidQueueStats "$@"
diff --git a/qpid/tools/src/java/bin/QpidRestAPI.sh b/qpid/tools/src/java/bin/QpidRestAPI.sh
new file mode 100755
index 0000000000..143e2ffde7
--- /dev/null
+++ b/qpid/tools/src/java/bin/QpidRestAPI.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/restapi.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.restapi.QpidRestAPI "$@"
diff --git a/qpid/tools/src/java/bin/QueueFuse.sh b/qpid/tools/src/java/bin/QueueFuse.sh
new file mode 100755
index 0000000000..8f04650b72
--- /dev/null
+++ b/qpid/tools/src/java/bin/QueueFuse.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar
+
+# Get the log level from the AMQJ_LOGGING_LEVEL environment variable.
+if [ -n "$AMQJ_LOGGING_LEVEL" ]; then
+ PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL
+fi
+
+java -cp $CLASSPATH $PROPERTIES org.apache.qpid.qmf2.tools.QueueFuse "$@"
diff --git a/qpid/tools/src/java/bin/log4j.xml b/qpid/tools/src/java/bin/log4j.xml
new file mode 100644
index 0000000000..434bb73259
--- /dev/null
+++ b/qpid/tools/src/java/bin/log4j.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <param name="Threshold" value="ALL"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%m%n"/>
+ </layout>
+ </appender>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+ <root>
+ <priority value="FATAL" />
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
diff --git a/qpid/tools/src/java/bin/qpid-web/authentication/account.properties b/qpid/tools/src/java/bin/qpid-web/authentication/account.properties
new file mode 100644
index 0000000000..082c50fc70
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/authentication/account.properties
@@ -0,0 +1,3 @@
+#
+guest=guest
+admin=admin
diff --git a/qpid/tools/src/java/bin/qpid-web/web/apple-touch-icon.png b/qpid/tools/src/java/bin/qpid-web/web/apple-touch-icon.png
new file mode 100644
index 0000000000..ad4478ccac
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/apple-touch-icon.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/favicon.ico b/qpid/tools/src/java/bin/qpid-web/web/favicon.ico
new file mode 100644
index 0000000000..1f61b0edd2
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/favicon.ico
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/index.html b/qpid/tools/src/java/bin/qpid-web/web/index.html
new file mode 100755
index 0000000000..7419feb02e
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/index.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+
+<!--
+This page provides a "welcome" page for the Qpid REST Service it immediately redirects to ui/qmf.html
+which requires authentication. The main reason for this page is to provide a "welcome" screen prior to
+the browser's authentication popup appearing, which makes it more obvious that it's the Qpid REST Service
+that is requesting authentication.
+-->
+<html>
+<head>
+ <title>QMF Console</title>
+ <link rel="stylesheet" type="text/css" href="/qmf-ui/css/index.css"/>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+
+ <!-- Changes the logical window size used when displaying a page on iOS. -->
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
+
+ <noscript>
+ <meta http-equiv="refresh" content="2; URL=/ui/qmf.html">
+ </noscript>
+
+ <script>
+ <!--
+ window.onload=function()
+ { // Do redirect
+ window.location.replace("/ui/qmf.html");
+ }
+ //-->
+ </script>
+
+</head>
+
+<body>
+ <div class="logo"></div>
+</body>
+
+</html>
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/css/LICENCE b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/LICENCE
new file mode 100644
index 0000000000..9951afb272
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/LICENCE
@@ -0,0 +1,29 @@
+/*
+ * itablet.css
+ * itablet-ie9.css
+ * itablet-ie8.css
+ * itablet-ie7.css
+ * itablet-ie6.css
+ *
+ * Copyright (c) 2013, Fraser Adams
+ *
+ * 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.
+ *
+ */
+
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie6.css b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie6.css
new file mode 100644
index 0000000000..d5bb6e349a
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie6.css
@@ -0,0 +1,302 @@
+/**
+ * Stylesheet to try and make things look not *too* bad in IE6 and below. Supporting IE6 really is a nightmare :-(
+ */
+
+/* Needed to get rid of annoying "permanent" IE6 scrollbar. */
+html
+{
+ overflow: hidden;
+}
+
+/* Explicitly setting height to 100% avoids some evil IE6 layout bugs */
+html, .sidebar, .main, .popup-window, .popup-container, .popup, .scroll-area
+{
+ height: 100%;
+}
+
+/* Explicitly setting width to 100% avoids some evil IE6 layout bugs */
+ul.list, .popup, .scroll-area
+{
+ width: 100%;
+}
+
+#sidebar-wrapper /* Make sure IE "hasLayout" is enabled by doing zoom: 1. */
+{
+ zoom: 1;
+}
+
+/* IE6 doesn't support color: inherit so we have to set it explicitly. */
+ul li.grey a /* Grey text generally used to show inactive fields */
+{
+ color: #8f8f8f;
+}
+
+ul li a
+{
+ color: #060606;
+}
+
+ul li.active a
+{
+ color: #fff;
+}
+
+/* IE6 form has a default non-zero margin, so we need to zero it. */
+form
+{
+ margin: 0;
+}
+
+.sidebar .scroll-area
+{
+ border-right: 1px solid #000;
+}
+
+ul.list li.first-child
+{
+ border-top: 1px groove #fff;
+}
+
+ul.list li.last-child
+{
+ border-bottom: 2px groove #fff;
+}
+
+ul.list li a p
+{
+ right: 0;
+}
+
+ul.list li.arrow a p, ul.list li.multiline a div p
+{
+ right: 18px;
+}
+
+
+ul.list li.multiline a.icon p, ul.list li.multiline a.icon div p
+{
+ right: 4px;
+}
+
+/**
+ * white-space: nowrap; doesn't work especially well in IE6, so we set it to normal and constrain height.
+ * Unfortunately with the approach below ellipses aren't displayed, but it's the lesser of the evils.
+ * white-space: nowrap; does seem to work with an explicit width set, but doing that breaks loads of other things.
+ */
+ul li a p.sub, ul li a p.title
+{
+ white-space: normal;
+}
+
+ul li a p.title, ul li a p.sub
+{
+ height: 16px;
+}
+
+/* For IE6 we need to use a GIF instead of a PNG to make the input background transparent but still receive events. */
+input, textarea
+{
+ background: url(/itablet/images/ie/transparent.gif) repeat;
+}
+
+/**
+ * For IE6 button :before and :after don't work so we have to resort to some JavaScript to add extra classes and tags
+ * IE6 doesn't support PNG images with alpha transparency, so we use gifs, which are OK but a littly more jagged.
+ */
+
+a.button
+{
+ background: url(/itablet/images/ie/button-sprite.gif) 0px -30px repeat-x;
+}
+
+a.button .before
+{
+ position: absolute;
+ top: 0;
+ left: -5px;
+ width: 5px;
+ height: 30px;
+ background: url(/itablet/images/ie/button-sprite.gif) -18px 0;
+}
+
+a.button .after
+{
+ position: absolute;
+ top: 0;
+ right: -5px;
+ width: 5px;
+ height: 30px;
+ background: url(/itablet/images/ie/button-sprite.gif) -13px 0;
+}
+
+a.button:active
+{
+ background-color: #766d69;
+ background-position: 0px -60px;
+}
+
+a.button:active .before
+{
+ background-position: -41px 0;
+}
+
+a.button:active .after
+{
+ background-position: -36px 0;
+}
+
+a.button.back .before
+{
+ position: absolute;
+ left: -13px;
+ width: 13px;
+ height: 30px;
+ background-position: 0 0;
+}
+
+a.button.back:active .before
+{
+ background-position: -23px 0;
+}
+
+a.button.blue
+{
+ background: url(/itablet/images/ie/blue-button-sprite.gif) 0px -30px repeat-x;
+}
+
+a.button.blue .before
+{
+ background: url(/itablet/images/ie/blue-button-sprite.gif) -18px 0;
+}
+
+a.button.blue .after
+{
+ background: url(/itablet/images/ie/blue-button-sprite.gif) -13px 0;
+}
+
+a.button.blue-back .before
+{
+ background-position: 0 0;
+}
+
+a.button.blue:active
+{
+ background-color: #6b6f76;
+ background-position: 0px -60px;
+}
+
+a.button.blue:active .before
+{
+ background-position: -41px 0;
+}
+
+a.button.blue:active .after
+{
+ background-position: -36px 0;
+}
+
+a.button.blue-back:active .before
+{
+ background-position: -23px 0;
+}
+
+.popup-window
+{
+ background: url(/itablet/images/ie/transparent.gif);
+ filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/ie/transparent.png', sizingMethod='scale');
+}
+
+.popup-window.smoked
+{
+ background: url(/itablet/images/ie/transparent.gif);
+ filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/ie/smoked.png', sizingMethod='scale');
+}
+
+div.mask
+{
+ background: url(/itablet/images/ie/transparent.gif);
+ filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/mask.png', sizingMethod='crop');
+}
+
+div.onoff
+{
+ background: url(/itablet/images/ie/transparent.gif);
+ filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/on_off.png', sizingMethod='crop');
+}
+
+/**
+ * Unfortunately AlphaImageLoader doesn't play nicely with alignment and these images need to be right aligned.
+ * Fortunately the single level of transparency allowed by gif images is good enough and only a little granier.
+ */
+
+ul.list li.arrow.radio
+{
+ background: #f7f7f7;
+}
+
+ul.list li.radio label
+{
+ padding: 0 11px 0 11px; /* top right bottom left */
+}
+
+ul li.active, ul.list li.radio.active, ul.list li.radio.ie6-checked-active /* Highlight in blue with white text */
+{
+ background: #035de7;
+}
+
+ul li.arrow
+{
+ background: url(/itablet/images/ie/chevron.gif) no-repeat right;
+}
+
+ul.list li.arrow
+{
+ background: #f7f7f7 url(/itablet/images/ie/chevron.gif) no-repeat right;
+}
+
+ul li.ie6-arrow-active, ul.list li.ie6-arrow-active
+{
+ background: #035de7 url(/itablet/images/ie/chevron-active.gif) no-repeat right;
+}
+
+ul.list li.radio.checked label
+{
+ background: url(/itablet/images/ie/tick.gif) no-repeat right;
+}
+
+ul.list li.radio.ie6-checked-active label
+{
+ background: url(/itablet/images/ie/tick-active.gif) no-repeat right;
+}
+
+ul.list li.ie6-radio-arrow
+{
+ background: #f7f7f7 url(/itablet/images/ie/blue-chevron.gif) no-repeat right;
+}
+
+ul.list li.ie6-radio-arrow label
+{
+ padding: 0 11px 0 32px; /* top right bottom left */
+}
+
+ul.list li.ie6-radio-arrow a
+{
+ height: 0;
+ width: 0;
+}
+
+ul.list li.ie6-checked-arrow label
+{
+ background: url(/itablet/images/ie/tick.gif) no-repeat 11px;
+}
+
+ul.list li.ie6-radio-arrow-active, ul.list li.ie6-checked-arrow-active
+{
+ background: #035de7 url(/itablet/images/ie/blue-chevron.gif) no-repeat right;
+}
+
+ul.list li.ie6-checked-arrow-active label
+{
+ background: url(/itablet/images/ie/tick-active.gif) no-repeat 11px;
+}
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie7.css b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie7.css
new file mode 100644
index 0000000000..d7a5b092eb
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie7.css
@@ -0,0 +1,193 @@
+/**
+ * Stylesheet to try and make things look not *too* bad in IE7.
+ */
+
+/* Needed to get rid of annoying "permanent" IE7 scrollbar. */
+html
+{
+ overflow: hidden;
+}
+
+#sidebar-wrapper /* Make sure IE "hasLayout" is enabled by doing zoom: 1. */
+{
+ zoom: 1;
+}
+
+/* IE7 doesn't correctly size the scrollbar without this, however it causes IE6 problems. */
+.page
+{
+ height: 100%;
+}
+
+ul.list
+{
+ width: 100%;
+}
+
+/* IE < 8 doesn't support color: inherit so we have to set it explicitly. */
+ul li.grey a /* Grey text generally used to show inactive fields */
+{
+ color: #8f8f8f;
+}
+
+ul li a
+{
+ color: #060606;
+}
+
+ul li.active a
+{
+ color: #fff;
+}
+
+/* IE7 gives this anchor a default size which adds extra visible padding. As the navigable radio button has */
+/* reskinned the markup around this li the anchor doesn't actually need to be visible so we can safely hide it. */
+ul.list li.arrow.radio a
+{
+ display: none;
+}
+
+/* IE < 8 form has a default non-zero margin, so we need to zero it. */
+form
+{
+ margin: 0;
+}
+
+/* For IE7 :before and :after don't work so we have to resort to some JavaScript to inject extra classes and tags */
+ul.list li:first-child
+{
+ border-top: 3px groove #fff; /* IE7 without hasLayout set doesn't show the border if it's less than 3px, why??? */
+}
+
+ul.list li:first-child > .fbefore, /* Use fbefore not before in case first-child and last-child apply to same element. */
+ul.list li:first-child > .fafter /* Use fafter not after in case first-child and last-child apply to same element. */
+{
+ position: absolute;
+ top: -3px;
+ left: -2px;
+ width: 10px;
+ height: 10px;
+ z-index: 1;
+ background: url(/itablet/images/ie/radius-10px-sprite.png);
+}
+
+ul.list li:first-child > .fafter /* Use fafter not after in case first-child and last-child apply to same element. */
+{
+ left: auto;
+ right: -2px;
+ background-position: -10px 0;
+}
+
+/* The fake rounded corners for the IE8 stylesheet more or less work, but the bottom offset in IE7 is different??? */
+ul.list li.last-child
+{
+ margin-top: -1px; /* Weird IE7 specific bug needs this set to -1px to render it as 0px!!!! */
+}
+
+ul.list li.last-child > .before, ul.list li.last-child > .after
+{
+ bottom: -1px;
+}
+
+/* For IE7 button :before and :after don't work so we have to resort to some JavaScript to add extra classes and tags */
+
+a.button .before
+{
+ position: absolute;
+ top: 0;
+ left: -5px;
+ width: 5px;
+ height: 30px;
+ background: url(/itablet/images/button-sprite.png) -18px 0;
+}
+
+a.button .after
+{
+ position: absolute;
+ top: 0;
+ right: -5px;
+ width: 5px;
+ height: 30px;
+ background: url(/itablet/images/button-sprite.png) -13px 0;
+}
+
+a.button:active .before
+{
+ background-position: -41px 0;
+}
+
+a.button:active .after
+{
+ background-position: -36px 0;
+}
+
+a.button.back .before
+{
+ position: absolute;
+ left: -13px;
+ width: 13px;
+ height: 30px;
+ background-position: 0 0;
+}
+
+a.button.back:active .before
+{
+ background-position: -23px 0;
+}
+
+a.button.blue .before
+{
+ background: url(/itablet/images/blue-button-sprite.png) -18px 0;
+}
+
+a.button.blue .after
+{
+ background: url(/itablet/images/blue-button-sprite.png) -13px 0;
+}
+
+a.button.back.blue .before
+{
+ background-position: 0 0;
+}
+
+a.button.blue:active .before
+{
+ background-position: -41px 0;
+}
+
+a.button.blue:active .after
+{
+ background-position: -36px 0;
+}
+
+a.button.back.blue:active .before
+{
+ background-position: -23px 0;
+}
+
+/* The horiz-checkbox class hasLayout set so the styles below go back to the correct values. */
+/* Unfortunately simply giving ul.list li hasLayout using zoom: 1 above causes the IE7 margin bug to trigger */
+/* so can't default to that hence the weird values for ul.list li.last-child/ul.list li.last-child > .before */
+/* ul.list li.last-child > .after There may be easier ways, but fixing one IE7 bug seems to cause other ones */
+ul.list li.horiz-checkbox:first-child, ul.list li.textarea:first-child
+{
+ border-top: 1px groove #fff;
+}
+
+ul.list li.horiz-checkbox.last-child, ul.list li.textarea.last-child
+{
+ margin-top: 0;
+}
+
+ul.list li.horiz-checkbox:first-child > .fbefore, ul.list li.horiz-checkbox:first-child > .fafter,
+ul.list li.textarea:first-child > .fbefore, ul.list li.textarea:first-child > .fafter
+{
+ top: -1px;
+}
+
+ul.list li.horiz-checkbox.last-child > .before, ul.list li.horiz-checkbox.last-child > .after,
+ul.list li.textarea.last-child > .before, ul.list li.textarea.last-child > .after
+{
+ bottom: -2px;
+}
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie8.css b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie8.css
new file mode 100644
index 0000000000..455a40a3e2
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie8.css
@@ -0,0 +1,140 @@
+/**
+ * Stylesheet to try and make things look not *too* bad in IE8 and below
+ */
+
+/**
+ * To handle opacity in IE < 9 we animate progid:DXImageTransform.Microsoft.gradient in itablet.js
+ * We use a transparent background image rather than background: transparent to block mouse events to the main page.
+ * progid:DXImageTransform messes with the font so we only use it for animating and use a 50% alpha png as end style.
+ */
+.popup-window, input, textarea
+{
+ background: url(/itablet/images/ie/transparent.png) repeat;
+}
+
+.popup-window.smoked
+{
+ background: url(/itablet/images/ie/smoked.png) repeat;
+}
+
+/**
+ * Create fake top rounded corners using images. Fortunately we can do this using pure CSS as ie8 supports
+ * :first-child, :before and :after so we supply the images as content.
+ */
+
+.header:before, .header:after
+{
+ position: absolute;
+ content: "";
+ top: 0;
+ left: 0;
+ width: 5px;
+ height: 5px;
+ background: url(/itablet/images/ie/radius-5px-sprite.png);
+}
+
+.header:after
+{
+ left: auto;
+ right: 0;
+ background-position: -5px;
+}
+
+ul.list li:first-child:before, ul.list li:first-child:after,
+ul.horiz-checkbox li.horiz-checkbox:first-child:before, ul.list li.horiz-checkbox:first-child label.first-child:before,
+ul.horiz-checkbox li.horiz-checkbox:first-child:after, ul.list li.horiz-checkbox:first-child label.last-child:after
+{
+ position: absolute;
+ content: "";
+ top: -2px;
+ left: -2px;
+ width: 10px;
+ height: 10px;
+ background: url(/itablet/images/ie/radius-10px-sprite.png);
+}
+
+ul.list li:first-child:after,
+ul.horiz-checkbox li.horiz-checkbox:first-child:after, ul.list li.horiz-checkbox:first-child label.last-child:after
+{
+ left: auto;
+ right: -2px;
+ background-position: -10px 0;
+}
+
+/**
+ * Create fake bottom rounded corners using images. Unfortunately this isn't as easy as the top corners because
+ * a) ie8 doesn't support :last-child and b) if we have a single list item we've already used :before and :after
+ * Unfortunately we have to resort to some JavaScript so itablet.js has some ie8 specific code to add a
+ * "last-child" class and prepend/append div elements with "before" and "after" classes. Fortunately this is
+ * fairly clean to do using jQuery using $("ul.list li:last-child") to find the item that we need to modify.
+ */
+
+ul.list li.last-child
+{
+ border-bottom: 2px groove #fff;
+}
+
+ul.list li.last-child > .before, ul.list li.last-child > .after
+{
+ position: absolute;
+ bottom: -2px;
+ left: -2px;
+ width: 10px;
+ height: 10px;
+ z-index: 1;
+ background: url(/itablet/images/ie/radius-10px-sprite.png) 0 -10px;
+}
+
+ul.list li.last-child > .after
+{
+ left: auto;
+ right: -2px;
+ background-position: -10px -10px;
+}
+
+/**
+ * For IE < 9 use solid background colour instead of a gradient - no bigee, it was a subtle gradient anyway.
+ */
+ul li.active, ul li.radio.checked.active /* Highlight in blue with white text */
+{
+ background: #035de7;
+}
+
+ul li.active.arrow
+{
+ background: #035de7 url(/itablet/images/chevron-active.png) no-repeat right;
+}
+
+ul.list li.arrow.radio.active
+{
+ background: #035de7 url(/itablet/images/blue-chevron.png) no-repeat right;
+}
+
+/**
+ * We need to apply the fake border radius to the labels in the horiz-checkbox too as child elements aren't clipped.
+ * Unfortunately IE8 doesn't seem to distinguish between the selectors ul.list li:first-child:before and
+ * ul.list li.horiz-checkbox:first-child:before when horiz-checkbox is dynamically added (though it does if it's
+ * placed in the static HTML) this stops the <li> fake radiused border being correctly repositioned
+ * for horiz-checkboxes. By adding horiz-checkbox to the <ul> too we can use a more explicit rule in the CSS.
+ */
+
+/* First we remove the original borders that were previously added for ul.list li:first-child:before and after. */
+ul.list li.horiz-checkbox:first-child:before, ul.list li.horiz-checkbox:first-child:after
+{
+ content: ".";
+}
+
+/* The we re-add them in the correct position using the more explicit rule on ul.horiz-checkbox */
+/* We need to add the rounded borders to the labels too as they are positioned above the li in the stack. */
+ul.horiz-checkbox li.horiz-checkbox:first-child:before, ul.list li.horiz-checkbox:first-child label.first-child:before,
+ul.horiz-checkbox li.horiz-checkbox:first-child:after, ul.list li.horiz-checkbox:first-child label.last-child:after
+{
+ top: -1px;
+}
+
+canvas /* For IE < 9 the radiused borders for the canvas are actually rendered on the canvas. */
+{
+ border: 0;
+}
+
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie9.css b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie9.css
new file mode 100644
index 0000000000..8af2058a70
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet-ie9.css
@@ -0,0 +1,24 @@
+/**
+ * Stylesheet to sort out IE9 specific quirks.......
+ */
+
+/**
+ * For some reason radiused borders cause IE9 to eat CPU when scrolling or animating in the popup window so remove them.
+ */
+
+.popup, .popup-container
+{
+ border-radius: 0;
+}
+
+.popup .scroll-area
+{
+ border-bottom-left-radius: 0;
+ border-bottom-right-radius: 0;
+}
+
+input
+{
+ padding: 12px 0 12px 0; /* top right bottom left */
+}
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet.css b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet.css
new file mode 100644
index 0000000000..82498634dd
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/css/itablet.css
@@ -0,0 +1,973 @@
+
+body
+{
+ font: 13px/1.5 Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif;
+ overflow-x: hidden; /* Hide horizontal scrollbar */
+ background: #dddddd;
+}
+
+p
+{
+ margin: 0;
+ padding: 11px 0 11px 0; /* top right bottom left */
+}
+
+.sidebar, .main, .popup-window, .popup-container, .popup, .scroll-area
+{
+ -moz-user-select: -moz-none; /* Disable selection on fields other than input & textarea. */
+ -webkit-user-select: none;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ background: #000;
+}
+
+.sidebar
+{
+ width: 250px;
+ border-right: 1px solid #000;
+ z-index: 2;
+}
+
+.main
+{
+ left: 251px;
+}
+
+.popup-window
+{
+ overflow: hidden;
+ background-color: rgba(0, 0, 0, 0.5);
+ z-index: 5;
+}
+
+.popup, .popup-container
+{
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+}
+
+.popup-container
+{
+ top: 64px;
+ bottom: 64px;
+ left: 20%;
+ right: 20%;
+
+ overflow-x: hidden;
+ box-shadow: 10px 10px 10px #777;
+}
+
+.scroll-area
+{
+ top: 44px;
+ overflow-x: hidden;
+ overflow-y: auto;
+ background: #dddddd;
+}
+
+div .mail
+{
+ background: #f5f5f5;
+}
+
+.popup .scroll-area
+{
+ -moz-border-bottom-left-radius: 5px;
+ -webkit-border-bottom-left-radius: 5px;
+ border-bottom-left-radius: 5px;
+ -moz-border-bottom-right-radius: 5px;
+ -webkit-border-bottom-right-radius: 5px;
+ border-bottom-right-radius: 5px;
+}
+
+.page
+{
+ padding: 31px 5% 31px 5%; /* top right bottom left */
+}
+
+.page h1
+{
+ color: #666666;
+ text-shadow: #fff 0 1px 0;
+ text-indent: 10px;
+ font-size: 17px;
+
+ margin: 0;
+ padding: 16px 0 4px 0; /* top right bottom left */
+}
+
+.page h1.first
+{
+ padding: 0 0 4px 0; /* top right bottom left */
+}
+
+.page p.note
+{
+ color: #717880;
+ text-shadow: #fff 0 1px 0;
+ text-align: center;
+ font-size: 15px;
+ font-weight: normal;
+
+ margin: 0;
+ padding: 4px 0 16px 0; /* top right bottom left */
+}
+
+.page p.note.nopadding
+{
+ padding-bottom: 0;
+}
+
+/*------------------------------------------- Header ------------------------------------------------*/
+
+div.header
+{
+ left: 0;
+ right: 0;
+ height: 43px;
+ line-height: 43px;
+
+ -moz-border-top-left-radius: 5px;
+ -webkit-border-top-left-radius: 5px;
+ border-top-left-radius: 5px;
+ -moz-border-top-right-radius: 5px;
+ -webkit-border-top-right-radius: 5px;
+ border-top-right-radius: 5px;
+ border-bottom: 1px solid #858b9b;
+
+ background: #bbb url(/itablet/images/ie/header-gradient.png) repeat-x;
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #999));
+ background: -webkit-linear-gradient(top center, #fff 0%, #999 100%);
+ background: -moz-linear-gradient(top center, #fff 0%, #999 100%);
+ background: -ms-linear-gradient(top center, #fff 0%, #999 100%);
+ background: -o-linear-gradient(top center, #fff 0%, #999 100%);
+ background: linear-gradient(top center, #fff 0%, #999 100%);
+}
+
+div.header h1
+{
+ text-align: center;
+ font-size: 20px;
+ font-weight: bold;
+ color: #717880;
+ text-shadow: #fff 0 1px 0;
+
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+
+ margin: 0 12px 0 12px; /* top right bottom left */
+}
+
+div.header a.back.button + h1
+{
+ margin: 0 88px 0 88px; /* top right bottom left */
+}
+
+div.header a.cancel.button + h1
+{
+ margin: 0 62px 0 62px; /* top right bottom left */
+}
+
+/*--------------------------------------- Header Buttons --------------------------------------------*/
+
+a.button
+{
+ outline: none;
+ text-decoration: none;
+ text-shadow: rgba(0, 0, 0, 0.6) 0 -1px 0;
+ color: #ddd;
+ background: #777;
+ font-size: 12px;
+ font-weight: bold;
+ line-height: 28px;
+
+ display: block;
+ position: absolute;
+ top: 7px;
+ left: 12px;
+ height: 30px;
+
+ background: url(/itablet/images/button-sprite.png) 0px -30px repeat-x;
+}
+
+a.button:before
+{
+ position: absolute;
+ content: "";
+ top: 0;
+ left: -5px;
+ width: 5px;
+ height: 30px;
+ background: url(/itablet/images/button-sprite.png) -18px 0 no-repeat;
+}
+
+a.button:after
+{
+ position: absolute;
+ content: "";
+ top: 0;
+ right: -5px;
+ width: 5px;
+ height: 30px;
+ background: url(/itablet/images/button-sprite.png) -13px 0 no-repeat;
+}
+
+a.button:active
+{
+ background-color: #766d69;
+ background-position: 0 -60px;
+}
+
+a.button:active:before
+{
+ background-position: -41px 0;
+}
+
+a.button:active:after
+{
+ background-position: -36px 0;
+}
+
+a.button.back
+{
+ left: 20px;
+}
+
+a.button.back:before
+{
+ position: absolute;
+ left: -13px;
+ width: 13px;
+ height: 30px;
+ background-position: 0 0;
+}
+
+a.button.back:active:before
+{
+ background-position: -23px 0;
+}
+
+a.button.right
+{
+ left: auto;
+ right: 12px;
+}
+
+a.button.blue
+{
+ color: #fff;
+ background: url(/itablet/images/blue-button-sprite.png) 0px -30px repeat-x;
+}
+
+a.button.blue:before
+{
+ background: url(/itablet/images/blue-button-sprite.png) -18px 0 no-repeat;
+}
+
+a.button.blue:after
+{
+ background: url(/itablet/images/blue-button-sprite.png) -13px 0 no-repeat;
+}
+
+a.button.back.blue:before
+{
+ background-position: 0 0;
+}
+
+a.button.blue:active
+{
+ background-color: #6b6f76;
+ background-position: 0px -60px;
+}
+
+a.button.blue:active:before
+{
+ background-position: -41px 0;
+}
+
+a.button.blue:active:after
+{
+ background-position: -36px 0;
+}
+
+a.button.back.blue:active:before
+{
+ background-position: -23px 0;
+}
+
+/*----------------------------------- Toolbar and Stock Buttons -------------------------------------*/
+
+span.toolbar
+{
+ position: absolute;
+ overflow: hidden;
+ top: 7px;
+ left: auto;
+ right: 12px;
+}
+
+span.toolbar a
+{
+ outline: none;
+ text-decoration: none;
+ display: block;
+ float: left;
+ width: 32px;
+ height: 32px;
+}
+
+a.delete
+{
+ background: url(/itablet/images/delete.png) no-repeat left;
+}
+
+a.add
+{
+ background: url(/itablet/images/add.png) no-repeat left;
+}
+
+a.home
+{
+ background: url(/itablet/images/home.png) no-repeat left;
+}
+
+a.flag
+{
+ background: url(/itablet/images/flag.png) no-repeat left;
+}
+
+a.move
+{
+ background: url(/itablet/images/move.png) no-repeat left;
+}
+
+a.bin
+{
+ background: url(/itablet/images/bin.png) no-repeat left;
+}
+
+a.action
+{
+ background: url(/itablet/images/action.png) no-repeat left;
+}
+
+a.write
+{
+ background: url(/itablet/images/write.png) no-repeat left;
+}
+
+/* Add a "glowing" highlight to toolbar and clickable icons */
+span.toolbar a:active:before,
+ul.list li.clickable-icon a:active:before
+{
+ position: absolute;
+ content: "";
+ top: 0;
+ left: 0;
+ width: 32px;
+ height: 100%;
+ background: url(/itablet/images/ie/radial-gradient.png) no-repeat left;
+ background: -webkit-gradient(radial, center center, 0, center center, 16, from(rgba(255,255,255,1)), to(rgba(200,200,200,0)));
+ background: -webkit-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%);
+ background: -moz-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%);
+ background: -ms-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%);
+ background: -o-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%);
+ background: radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%);
+}
+
+span.toolbar a:active:before
+{
+ position: relative;
+ float: left;
+}
+
+/*---- this is hidden for desktop browsers it is shown by the styles enabled by the media query -----*/
+
+div.header a.menu
+{
+ display: none;
+}
+
+/*------------------------------- Define the styles for list elements -------------------------------*/
+
+ul
+{
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+
+ul li
+{
+ position: relative;
+ line-height: 42px;
+ padding: 1px 0 0 0; /* top right bottom left */
+
+ color: #060606;
+ font-size: 17px;
+ font-weight: bold;
+ border-bottom: 1px solid #ccc;
+}
+
+ul.list li
+{
+ line-height: 21px;
+ padding: 11px 0 11px 0;
+
+ background-color: #f7f7f7;
+ border-left: 2px groove #fff;
+ border-right: 2px groove #fff;
+}
+
+ul.list li.multiline, ul.list li.icon, ul.list li.clickable-icon
+{
+ padding: 5px 0 5px 0;
+}
+
+ul.list li:first-child
+{
+ -moz-border-top-left-radius: 10px;
+ -webkit-border-top-left-radius: 10px;
+ border-top-left-radius: 10px;
+ -moz-border-top-right-radius: 10px;
+ -webkit-border-top-right-radius: 10px;
+ border-top-right-radius: 10px;
+ border-top: 2px groove #fff;
+}
+
+ul.list li:last-child
+{
+ -moz-border-bottom-left-radius: 10px;
+ -webkit-border-bottom-left-radius: 10px;
+ border-bottom-left-radius: 10px;
+ -moz-border-bottom-right-radius: 10px;
+ -webkit-border-bottom-right-radius: 10px;
+ border-bottom-right-radius: 10px;
+ border-bottom: 2px groove #fff;
+}
+
+ul.mail li
+{
+ line-height: 24px;
+ padding-bottom: 3px;
+}
+
+ul li.pop
+{
+ text-align: center;
+}
+
+ul li.radio.checked /* Adjust text colour on selected radio item */
+{
+ color: #385487;
+ background: #f7f7f7;
+}
+
+ul li.grey /* Grey text generally used to show inactive fields */
+{
+ color: #8f8f8f;
+}
+
+ul li.active, ul li.radio.checked.active /* Highlight in blue with white text */
+{
+ background: #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x;
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7));
+ background: -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: -o-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ color: #fff;
+}
+
+/*------------------------------ Define the styles for anchor elements ------------------------------*/
+
+input, textarea, a
+{
+ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); /* Hide the tap highlighting by making it transparent. */
+}
+
+a
+{
+ -webkit-touch-callout: none;
+ cursor: default; /* Disable the "hand" cursor over anchors. */
+}
+
+ul li a
+{
+ outline: none;
+ text-decoration: none; /* Hide the underline */
+ color: inherit; /* Get the text colour from the item containing the anchor. */
+ display: block; /* Treat anchor as a block element - needed to correctly display image. */
+}
+
+
+ul.list li a, label, ul.list li.arrow a, ul.mail li a, ul.list li.multiline a div
+{
+ position: relative;
+ padding: 0 11px 0 11px; /* top right bottom left */
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+}
+
+ul.list li.arrow a, ul.mail li.arrow a
+{
+ padding-right: 30px; /* When a list item has a chevron we need to increase anchor right padding past it. */
+}
+
+ul li.icon a, ul li.clickable-icon a
+{
+ margin-left: 5px;
+ text-indent: 40px;
+}
+
+ul.list li.icon a, ul.list li.clickable-icon a
+{
+ margin-left: 8px;
+ text-indent: 30px;
+
+ /* For icon/clickable-icon when not a multiline item we need to increase anchor top and bottom padding so
+ that we don't end up clipping the top and bottom off the icon. */
+ padding-top: 5px;
+ padding-bottom: 5px;
+}
+
+ul.mail li a
+{
+ left: 8px;
+ text-indent: 18px; /* Indents the text to the right of the image. */
+}
+
+ul.mail li.unread a
+{
+ background: url(/itablet/images/blueball.png) no-repeat left;
+}
+
+
+ul li.arrow
+{
+ text-align: left; /* This resets alignment in case class="pop arrow" is used because pop centre aligns. */
+ background: url(/itablet/images/chevron.png) no-repeat right;
+}
+
+ul.list li.arrow
+{
+ background: #f7f7f7 url(/itablet/images/chevron.png) no-repeat right;
+}
+
+ul li.active.arrow
+{
+ background: url(/itablet/images/chevron-active.png) no-repeat right, #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x;
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7));
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -o-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, linear-gradient(top center, #058cf7 0%, #035de7 100%);
+}
+
+/*--------------------------- Define the styles for right justified text ----------------------------*/
+
+ul li a p
+{
+ position: absolute;
+ top: 0;
+ right: 11px;
+
+ padding: 0;
+ width: 50%;
+ text-align: right;
+ text-indent: 0;
+
+ color: #464646;
+ font-weight: normal;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+}
+
+ul li a p.fullwidth
+{
+ width: 100%;
+}
+
+ul li a p.date
+{
+ color: #3078da;
+ font-size: 13px;
+}
+
+ul li.arrow a p
+{
+ right: 30px;
+}
+
+/*----------------------------- Define the styles for multiline items -------------------------------*/
+
+ul.list li.multiline a
+{
+ padding-top: 0px;
+ padding-bottom: 0px;
+}
+
+ul.list li.multiline a div
+{
+ padding: 0;
+}
+
+ul.list li.multiline a div p
+{
+ right: 0;
+}
+
+ul li a p.sub, ul li a p.title
+{
+ position: relative;
+ top: 0;
+ left: 0;
+
+ width: auto;
+ text-align: left;
+
+ color: gray;
+ font-size: 14px;
+ line-height: 16px;
+}
+
+ul li a p.title
+{
+ color: #060606;
+}
+
+ul.list li.icon a p.sub, ul.list li.clickable-icon a p.sub,
+ul.list li.icon a p.title, ul.list li.clickable-icon a p.title
+{
+ margin-left: 30px;
+}
+
+ul.mail li a p.sub, ul.mail li a p.title
+{
+ margin-left: 18px;
+}
+
+ul.mail li a p.sub
+{
+ font-size: 12px;
+ height: 33px;
+ white-space: normal;
+}
+
+ul li.active a p, ul.mail li.active a p
+{
+ color: #fff;
+}
+
+/*------------------------------- Define the styles for input fields --------------------------------*/
+
+label
+{
+ display: block;
+}
+
+label.input /* Adding the input class to a label will allow overflow truncation to work */
+{
+ width: 115px;
+}
+
+input, .placeholder
+{
+ position: absolute;
+ top: 0;
+ left: 115px;
+ right: 11px;
+ padding: 9px 0 9px 0; /* top right bottom left */
+ border: 0;
+ font: 17px Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif;
+}
+
+
+.placeholder.textarea
+{
+ left: 11px;
+ font-size: 12px
+}
+
+.placeholder /* Used to fake HTML5 input placeholders in browsers that don't have native support. */
+{
+ padding: 12px 0 12px 0; /* top right bottom left */
+ color: #9f9f9f;
+}
+
+input.error, textarea.error
+{
+ -webkit-appearance: none;
+ moz-box-shadow: 0 0 4px red;
+ webkit-box-shadow: 0 0 4px red;
+ box-shadow: 0 0 4px red;
+}
+
+textarea
+{
+ position: relative; /* Needs to be set for fake placeholders to work properly - the z-index needs to be 1 */
+
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+
+ resize: vertical;
+
+ width: 100%;
+ height: 100px;
+
+ border: 0;
+ padding: 0 11px 0 11px;
+
+ overflow: auto;
+}
+
+/*
+ For fake placeholders to work we want to ensure the input/textarea is in the foreground and receiving events,
+ but we also need them to be transparent so we can see the placeholder through them.
+*/
+input, textarea
+{
+ background: rgba(0, 0, 0, 0);
+ z-index: 1;
+}
+
+/*---------------------------- Define the styles for radio button widget ----------------------------*/
+
+ul.list li.radio label
+{
+ padding: 0 32px 0 11px; /* top right bottom left */
+}
+
+ul.list li.radio.checked label
+{
+ background: url(/itablet/images/tick.png) no-repeat right;
+}
+
+ul.list li.radio.active.checked label
+{
+ background: url(/itablet/images/tick-active.png) no-repeat right;
+}
+
+ul.list li.arrow.radio
+{
+ background: #f7f7f7 url(/itablet/images/blue-chevron.png) no-repeat right;
+}
+
+ul.list li.arrow.radio.active
+{
+ background: url(/itablet/images/blue-chevron.png) no-repeat right, #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x;
+ background: url(/itablet/images/blue-chevron.png) no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7));
+ background: url(/itablet/images/blue-chevron.png) no-repeat right, -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/blue-chevron.png) no-repeat right, -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/blue-chevron.png) no-repeat right, -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/blue-chevron.png) no-repeat right, -o-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/blue-chevron.png) no-repeat right, linear-gradient(top center, #058cf7 0%, #035de7 100%);
+}
+
+ul.list li.arrow.radio label
+{
+ padding: 0 38px 0 32px; /* top right bottom left */
+}
+
+ul.list li.arrow.radio.checked label
+{
+ background: url(/itablet/images/tick.png) no-repeat 11px;
+}
+
+ul.list li.arrow.radio.active.checked label
+{
+ background: url(/itablet/images/tick-active.png) no-repeat 11px;
+}
+
+/*------------------------------ Define the styles for checkbox widget ------------------------------*/
+
+div.checkbox
+{
+ position: absolute;
+ overflow: hidden; /* clip the child div to the size of this one */
+ top: 7px;
+ right: 11px;
+ width: 77px;
+ height: 27px;
+}
+
+div.mask
+{
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ z-index: 1;
+ background: url(/itablet/images/mask.png) no-repeat;
+}
+
+div.onoff
+{
+ position: absolute;
+ top: 0;
+ left: -50px;
+ width: 127px;
+ height: 27px;
+ background: url(/itablet/images/on_off.png) no-repeat;
+}
+
+/*------------------------- Define the styles for horizontal checkbox widget ------------------------*/
+
+ul.list li.horiz-checkbox
+{
+ display: block;
+ padding: 0;
+ line-height: 40px;
+ background: url(/itablet/images/toggle-off.png) repeat-x;
+}
+
+ul.list li.horiz-checkbox label
+{
+ color: #717880;
+ text-shadow: #fff 0 1px 0;
+
+ display: inline-block;
+ vertical-align: bottom;
+ text-align: center;
+ padding: 0;
+ width: 100%;
+ background: url(/itablet/images/toggle-off.png) repeat-x;
+}
+
+ul.list li.horiz-checkbox label span
+{
+ position: absolute;
+ top: 0;
+ right: 0;
+ height: 100%;
+ border-right: 1px solid #828278;
+}
+
+/* Use toggle-on class not checked to avoid IE6 confusing with a radio button as IE6 doesn't support multiple classes. */
+ul.list li.horiz-checkbox.toggle-on, ul.list li.horiz-checkbox label.checked
+{
+ color: #fff;
+ text-shadow: 0 0 0 #000; /* passing all the arguments will reset it to nothing */
+ background: url(/itablet/images/toggle-on.png) repeat-x;
+}
+
+ul.list li.horiz-checkbox label.checked span
+{
+ border-right: 0;
+ width: 5px;
+ height: 40px;
+ background: url(/itablet/images/toggle-on-border.png) no-repeat right;
+}
+
+ul.list li.horiz-checkbox:first-child
+{
+ border-top: 1px groove #fff;
+}
+
+/* Need to apply border radius to the labels in the horiz-checkbox too as child elements aren't clipped. */
+
+ul.list li.horiz-checkbox:first-child label.first-child
+{
+ -moz-border-top-left-radius: 10px;
+ -webkit-border-top-left-radius: 10px;
+ border-top-left-radius: 10px;
+}
+
+ul.list li.horiz-checkbox:first-child label.last-child
+{
+ -moz-border-top-right-radius: 10px;
+ -webkit-border-top-right-radius: 10px;
+ border-top-right-radius: 10px;
+}
+
+ul.list li.horiz-checkbox:last-child label.first-child
+{
+ -moz-border-bottom-left-radius: 10px;
+ -webkit-border-bottom-left-radius: 10px;
+ border-bottom-left-radius: 10px;
+}
+
+ul.list li.horiz-checkbox:last-child label.last-child
+{
+ -moz-border-bottom-right-radius: 10px;
+ -webkit-border-bottom-right-radius: 10px;
+ border-bottom-right-radius: 10px;
+}
+
+/*-------------------------------- Style for the HTML5 drawing canvas -------------------------------*/
+/* N.B. By the standard, CSS does not size the canvas coordinate system, it scales the content. This */
+/* means that we can't style canvas width and height, these must be set via Javascript if we wish to */
+/* use relative sizes. */
+/*---------------------------------------------------------------------------------------------------*/
+canvas
+{
+ border: 2px groove #fff;
+ -moz-border-radius: 10px;
+ -webkit-border-radius: 10px;
+ border-radius: 10px;
+ background-color: #f6f6f6;
+ display: block;
+}
+
+
+
+
+/*---------------------------- Detect mobile sized screen via media query ---------------------------*/
+/*
+@media only screen and (max-width: 480px)
+*/
+
+@media only screen and (max-device-width: 480px),
+ only screen and (min-device-width: 640px) and (max-device-width: 1136px) and (-webkit-min-device-pixel-ratio: 2)
+{
+ .sidebar
+ {
+ width: 100%;
+ }
+
+ .main /* We check the .main left value in JavaScript if we want to detect mobile or non-mobile */
+ {
+ left: 0;
+ }
+
+ .popup-container
+ { /* For some reason the Android VM I'm using isn't respecting top & bottom of zero here iPhone is fine!! */
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ }
+
+ /* For mobile devices display the menu back buttons */
+ div.header a.menu
+ {
+ display: block;
+ }
+
+ .sidebar ul li
+ {
+ background: url(/itablet/images/chevron.png) no-repeat right;
+ }
+
+ .sidebar ul li.active
+ {
+ background: url(/itablet/images/chevron-active.png) no-repeat right, #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x;
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7));
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, -o-linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ background: url(/itablet/images/chevron-active.png) no-repeat right, linear-gradient(top center, #058cf7 0%, #035de7 100%);
+ }
+}
+
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/action.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/action.png
new file mode 100644
index 0000000000..af5e0378b0
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/action.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/add.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/add.png
new file mode 100644
index 0000000000..700d9f100e
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/add.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/bin.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/bin.png
new file mode 100644
index 0000000000..90923898af
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/bin.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-button-sprite.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-button-sprite.png
new file mode 100644
index 0000000000..9fedd12867
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-button-sprite.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-chevron.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-chevron.png
new file mode 100644
index 0000000000..41e539fc10
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blue-chevron.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blueball.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blueball.png
new file mode 100644
index 0000000000..a7c4c68349
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/blueball.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/button-sprite.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/button-sprite.png
new file mode 100644
index 0000000000..c15b4ea217
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/button-sprite.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron-active.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron-active.png
new file mode 100644
index 0000000000..86832ebc7b
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron-active.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron.png
new file mode 100644
index 0000000000..6421a16762
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/chevron.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/delete.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/delete.png
new file mode 100644
index 0000000000..74b1ff3ea1
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/delete.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/flag.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/flag.png
new file mode 100644
index 0000000000..0baf2a9986
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/flag.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/home.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/home.png
new file mode 100644
index 0000000000..4f359778a2
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/home.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/active-gradient.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/active-gradient.png
new file mode 100644
index 0000000000..6cd4404965
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/active-gradient.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-button-sprite.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-button-sprite.gif
new file mode 100644
index 0000000000..8edaddedd8
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-button-sprite.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-chevron.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-chevron.gif
new file mode 100644
index 0000000000..bb8f3d51d6
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/blue-chevron.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/button-sprite.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/button-sprite.gif
new file mode 100644
index 0000000000..5e920511d1
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/button-sprite.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron-active.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron-active.gif
new file mode 100644
index 0000000000..f37329bb3b
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron-active.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron.gif
new file mode 100644
index 0000000000..dce238269a
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/chevron.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/header-gradient.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/header-gradient.png
new file mode 100644
index 0000000000..d4e9a6c9f0
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/header-gradient.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radial-gradient.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radial-gradient.png
new file mode 100644
index 0000000000..d9ab361add
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radial-gradient.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-10px-sprite.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-10px-sprite.png
new file mode 100644
index 0000000000..ca91770e2f
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-10px-sprite.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-5px-sprite.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-5px-sprite.png
new file mode 100644
index 0000000000..c00e2194db
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/radius-5px-sprite.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/red6.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/red6.png
new file mode 100644
index 0000000000..c1c0ba1db9
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/red6.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/smoked.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/smoked.png
new file mode 100644
index 0000000000..ea6b7c587f
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/smoked.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick-active.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick-active.gif
new file mode 100644
index 0000000000..629f6f1eca
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick-active.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick.gif
new file mode 100644
index 0000000000..fdbdc1eec2
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/tick.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.gif b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.gif
new file mode 100755
index 0000000000..c5b2954ac6
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.png
new file mode 100644
index 0000000000..8ac7f64f1a
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/ie/transparent.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/mask.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/mask.png
new file mode 100644
index 0000000000..f8be0e6f36
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/mask.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/move.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/move.png
new file mode 100644
index 0000000000..80f77eeb72
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/move.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/on_off.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/on_off.png
new file mode 100644
index 0000000000..89243bf27d
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/on_off.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick-active.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick-active.png
new file mode 100644
index 0000000000..16fa8ca71b
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick-active.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick.png
new file mode 100644
index 0000000000..783b60fe9a
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/tick.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-off.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-off.png
new file mode 100644
index 0000000000..474ad3cd63
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-off.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on-border.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on-border.png
new file mode 100644
index 0000000000..7680cd7d0a
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on-border.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on.png
new file mode 100644
index 0000000000..275aa42114
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/toggle-on.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/images/write.png b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/write.png
new file mode 100644
index 0000000000..b7329dbf9f
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/images/write.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/LICENCE b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/LICENCE
new file mode 100644
index 0000000000..42cf8a1198
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/LICENCE
@@ -0,0 +1,72 @@
+/*
+ * itablet.js
+ *
+ * Copyright (c) 2013, Fraser Adams
+ *
+ * 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.
+ *
+ */
+
+
+/*
+ * jQuery JavaScript Library v1.7.1
+ * http://jquery.com/
+ *
+ * Copyright 2011, John Resig
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * Includes Sizzle.js
+ * http://sizzlejs.com/
+ * Copyright 2011, The Dojo Foundation
+ * Released under the MIT, BSD, and GPL Licenses.
+ *
+ * Date: Mon Nov 21 21:11:03 2011 -0500
+ */
+
+
+/*
+ * iscroll.js
+ *
+ * Copyright (c) 2011 Matteo Spinelli, http://cubiq.org/
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/iscroll.js b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/iscroll.js
new file mode 100644
index 0000000000..46330e51f7
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/iscroll.js
@@ -0,0 +1,1117 @@
+/*!
+ * iScroll v4.2 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org
+ * Released under MIT license, http://cubiq.org/license
+ */
+(function(window, doc){
+var m = Math,
+ dummyStyle = doc.createElement('div').style,
+ vendor = (function () {
+ var vendors = 't,webkitT,MozT,msT,OT'.split(','),
+ t,
+ i = 0,
+ l = vendors.length;
+
+ for ( ; i < l; i++ ) {
+ t = vendors[i] + 'ransform';
+ if ( t in dummyStyle ) {
+ return vendors[i].substr(0, vendors[i].length - 1);
+ }
+ }
+
+ return false;
+ })(),
+ cssVendor = vendor ? '-' + vendor.toLowerCase() + '-' : '',
+
+ // Style properties
+ transform = prefixStyle('transform'),
+ transitionProperty = prefixStyle('transitionProperty'),
+ transitionDuration = prefixStyle('transitionDuration'),
+ transformOrigin = prefixStyle('transformOrigin'),
+ transitionTimingFunction = prefixStyle('transitionTimingFunction'),
+ transitionDelay = prefixStyle('transitionDelay'),
+
+ // Browser capabilities
+ isAndroid = (/android/gi).test(navigator.appVersion),
+ isIDevice = (/iphone|ipad/gi).test(navigator.appVersion),
+ isTouchPad = (/hp-tablet/gi).test(navigator.appVersion),
+
+ has3d = prefixStyle('perspective') in dummyStyle,
+ hasTouch = 'ontouchstart' in window && !isTouchPad,
+ hasTransform = !!vendor,
+ hasTransitionEnd = prefixStyle('transition') in dummyStyle,
+
+ RESIZE_EV = 'onorientationchange' in window ? 'orientationchange' : 'resize',
+ START_EV = hasTouch ? 'touchstart' : 'mousedown',
+ MOVE_EV = hasTouch ? 'touchmove' : 'mousemove',
+ END_EV = hasTouch ? 'touchend' : 'mouseup',
+ CANCEL_EV = hasTouch ? 'touchcancel' : 'mouseup',
+ WHEEL_EV = vendor == 'Moz' ? 'DOMMouseScroll' : 'mousewheel',
+ TRNEND_EV = (function () {
+ if ( vendor === false ) return false;
+
+ var transitionEnd = {
+ '' : 'transitionend',
+ 'webkit' : 'webkitTransitionEnd',
+ 'Moz' : 'transitionend',
+ 'O' : 'oTransitionEnd',
+ 'ms' : 'MSTransitionEnd'
+ };
+
+ return transitionEnd[vendor];
+ })(),
+
+ nextFrame = (function() {
+ return window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function(callback) { return setTimeout(callback, 1); };
+ })(),
+ cancelFrame = (function () {
+ return window.cancelRequestAnimationFrame ||
+ window.webkitCancelAnimationFrame ||
+ window.webkitCancelRequestAnimationFrame ||
+ window.mozCancelRequestAnimationFrame ||
+ window.oCancelRequestAnimationFrame ||
+ window.msCancelRequestAnimationFrame ||
+ clearTimeout;
+ })(),
+
+ // Helpers
+ translateZ = has3d ? ' translateZ(0)' : '',
+
+ // Constructor
+ iScroll = function (el, options) {
+ var that = this,
+ i;
+
+ that.wrapper = typeof el == 'object' ? el : doc.getElementById(el);
+ that.wrapper.style.overflow = 'hidden';
+ that.scroller = that.wrapper.children[0];
+
+ // Default options
+ that.options = {
+ hScroll: true,
+ vScroll: true,
+ x: 0,
+ y: 0,
+ bounce: true,
+ bounceLock: false,
+ momentum: true,
+ lockDirection: true,
+ useTransform: true,
+ useTransition: false,
+ topOffset: 0,
+ checkDOMChanges: false, // Experimental
+ handleClick: true,
+
+ // Scrollbar
+ hScrollbar: true,
+ vScrollbar: true,
+ fixedScrollbar: isAndroid,
+ hideScrollbar: isIDevice,
+ fadeScrollbar: isIDevice && has3d,
+ scrollbarClass: '',
+
+ // Zoom
+ zoom: false,
+ zoomMin: 1,
+ zoomMax: 4,
+ doubleTapZoom: 2,
+ wheelAction: 'scroll',
+
+ // Snap
+ snap: false,
+ snapThreshold: 1,
+
+ // Events
+ onRefresh: null,
+ onBeforeScrollStart: function (e) { e.preventDefault(); },
+ onScrollStart: null,
+ onBeforeScrollMove: null,
+ onScrollMove: null,
+ onBeforeScrollEnd: null,
+ onScrollEnd: null,
+ onTouchEnd: null,
+ onDestroy: null,
+ onZoomStart: null,
+ onZoom: null,
+ onZoomEnd: null
+ };
+
+ // User defined options
+ for (i in options) that.options[i] = options[i];
+
+ // Set starting position
+ that.x = that.options.x;
+ that.y = that.options.y;
+
+ // Normalize options
+ that.options.useTransform = hasTransform && that.options.useTransform;
+ that.options.hScrollbar = that.options.hScroll && that.options.hScrollbar;
+ that.options.vScrollbar = that.options.vScroll && that.options.vScrollbar;
+ that.options.zoom = that.options.useTransform && that.options.zoom;
+ that.options.useTransition = hasTransitionEnd && that.options.useTransition;
+
+ // Helpers FIX ANDROID BUG!
+ // translate3d and scale doesn't work together!
+ // Ignoring 3d ONLY WHEN YOU SET that.options.zoom
+ if ( that.options.zoom && isAndroid ){
+ translateZ = '';
+ }
+
+ // Set some default styles
+ that.scroller.style[transitionProperty] = that.options.useTransform ? cssVendor + 'transform' : 'top left';
+ that.scroller.style[transitionDuration] = '0';
+ that.scroller.style[transformOrigin] = '0 0';
+ if (that.options.useTransition) that.scroller.style[transitionTimingFunction] = 'cubic-bezier(0.33,0.66,0.66,1)';
+
+ if (that.options.useTransform) that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px)' + translateZ;
+ else that.scroller.style.cssText += ';position:absolute;top:' + that.y + 'px;left:' + that.x + 'px';
+
+ if (that.options.useTransition) that.options.fixedScrollbar = true;
+
+ that.refresh();
+
+ that._bind(RESIZE_EV, window);
+ that._bind(START_EV);
+ if (!hasTouch) {
+ that._bind('mouseout', that.wrapper);
+ if (that.options.wheelAction != 'none')
+ that._bind(WHEEL_EV);
+ }
+
+ if (that.options.checkDOMChanges) that.checkDOMTime = setInterval(function () {
+ that._checkDOMChanges();
+ }, 500);
+ };
+
+// Prototype
+iScroll.prototype = {
+ enabled: true,
+ x: 0,
+ y: 0,
+ steps: [],
+ scale: 1,
+ currPageX: 0, currPageY: 0,
+ pagesX: [], pagesY: [],
+ aniTime: null,
+ wheelZoomCount: 0,
+
+ handleEvent: function (e) {
+ var that = this;
+ switch(e.type) {
+ case START_EV:
+ if (!hasTouch && e.button !== 0) return;
+ that._start(e);
+ break;
+ case MOVE_EV: that._move(e); break;
+ case END_EV:
+ case CANCEL_EV: that._end(e); break;
+ case RESIZE_EV: that._resize(); break;
+ case WHEEL_EV: that._wheel(e); break;
+ case 'mouseout': that._mouseout(e); break;
+ case TRNEND_EV: that._transitionEnd(e); break;
+ }
+ },
+
+ _checkDOMChanges: function () {
+ if (this.moved || this.zoomed || this.animating ||
+ (this.scrollerW == this.scroller.offsetWidth * this.scale && this.scrollerH == this.scroller.offsetHeight * this.scale)) return;
+
+ this.refresh();
+ },
+
+ _scrollbar: function (dir) {
+ var that = this,
+ bar;
+
+ if (!that[dir + 'Scrollbar']) {
+ if (that[dir + 'ScrollbarWrapper']) {
+ if (hasTransform) that[dir + 'ScrollbarIndicator'].style[transform] = '';
+ that[dir + 'ScrollbarWrapper'].parentNode.removeChild(that[dir + 'ScrollbarWrapper']);
+ that[dir + 'ScrollbarWrapper'] = null;
+ that[dir + 'ScrollbarIndicator'] = null;
+ }
+
+ return;
+ }
+
+ if (!that[dir + 'ScrollbarWrapper']) {
+ // Create the scrollbar wrapper
+ bar = doc.createElement('div');
+
+ if (that.options.scrollbarClass) bar.className = that.options.scrollbarClass + dir.toUpperCase();
+ else bar.style.cssText = 'position:absolute;z-index:100;' + (dir == 'h' ? 'height:7px;bottom:1px;left:2px;right:' + (that.vScrollbar ? '7' : '2') + 'px' : 'width:7px;bottom:' + (that.hScrollbar ? '7' : '2') + 'px;top:2px;right:1px');
+
+ bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:opacity;' + cssVendor + 'transition-duration:' + (that.options.fadeScrollbar ? '350ms' : '0') + ';overflow:hidden;opacity:' + (that.options.hideScrollbar ? '0' : '1');
+
+ that.wrapper.appendChild(bar);
+ that[dir + 'ScrollbarWrapper'] = bar;
+
+ // Create the scrollbar indicator
+ bar = doc.createElement('div');
+ if (!that.options.scrollbarClass) {
+ bar.style.cssText = 'position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);' + cssVendor + 'background-clip:padding-box;' + cssVendor + 'box-sizing:border-box;' + (dir == 'h' ? 'height:100%' : 'width:100%') + ';' + cssVendor + 'border-radius:3px;border-radius:3px';
+ }
+ bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:' + cssVendor + 'transform;' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);' + cssVendor + 'transition-duration:0;' + cssVendor + 'transform: translate(0,0)' + translateZ;
+ if (that.options.useTransition) bar.style.cssText += ';' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)';
+
+ that[dir + 'ScrollbarWrapper'].appendChild(bar);
+ that[dir + 'ScrollbarIndicator'] = bar;
+ }
+
+ if (dir == 'h') {
+ that.hScrollbarSize = that.hScrollbarWrapper.clientWidth;
+ that.hScrollbarIndicatorSize = m.max(m.round(that.hScrollbarSize * that.hScrollbarSize / that.scrollerW), 8);
+ that.hScrollbarIndicator.style.width = that.hScrollbarIndicatorSize + 'px';
+ that.hScrollbarMaxScroll = that.hScrollbarSize - that.hScrollbarIndicatorSize;
+ that.hScrollbarProp = that.hScrollbarMaxScroll / that.maxScrollX;
+ } else {
+ that.vScrollbarSize = that.vScrollbarWrapper.clientHeight;
+ that.vScrollbarIndicatorSize = m.max(m.round(that.vScrollbarSize * that.vScrollbarSize / that.scrollerH), 8);
+ that.vScrollbarIndicator.style.height = that.vScrollbarIndicatorSize + 'px';
+ that.vScrollbarMaxScroll = that.vScrollbarSize - that.vScrollbarIndicatorSize;
+ that.vScrollbarProp = that.vScrollbarMaxScroll / that.maxScrollY;
+ }
+
+ // Reset position
+ that._scrollbarPos(dir, true);
+ },
+
+ _resize: function () {
+ var that = this;
+ setTimeout(function () { that.refresh(); }, isAndroid ? 200 : 0);
+ },
+
+ _pos: function (x, y) {
+ if (this.zoomed) return;
+
+ x = this.hScroll ? x : 0;
+ y = this.vScroll ? y : 0;
+
+ if (this.options.useTransform) {
+ this.scroller.style[transform] = 'translate(' + x + 'px,' + y + 'px) scale(' + this.scale + ')' + translateZ;
+ } else {
+ x = m.round(x);
+ y = m.round(y);
+ this.scroller.style.left = x + 'px';
+ this.scroller.style.top = y + 'px';
+ }
+
+ this.x = x;
+ this.y = y;
+
+ this._scrollbarPos('h');
+ this._scrollbarPos('v');
+ },
+
+ _scrollbarPos: function (dir, hidden) {
+ var that = this,
+ pos = dir == 'h' ? that.x : that.y,
+ size;
+
+ if (!that[dir + 'Scrollbar']) return;
+
+ pos = that[dir + 'ScrollbarProp'] * pos;
+
+ if (pos < 0) {
+ if (!that.options.fixedScrollbar) {
+ size = that[dir + 'ScrollbarIndicatorSize'] + m.round(pos * 3);
+ if (size < 8) size = 8;
+ that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px';
+ }
+ pos = 0;
+ } else if (pos > that[dir + 'ScrollbarMaxScroll']) {
+ if (!that.options.fixedScrollbar) {
+ size = that[dir + 'ScrollbarIndicatorSize'] - m.round((pos - that[dir + 'ScrollbarMaxScroll']) * 3);
+ if (size < 8) size = 8;
+ that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px';
+ pos = that[dir + 'ScrollbarMaxScroll'] + (that[dir + 'ScrollbarIndicatorSize'] - size);
+ } else {
+ pos = that[dir + 'ScrollbarMaxScroll'];
+ }
+ }
+
+ that[dir + 'ScrollbarWrapper'].style[transitionDelay] = '0';
+ that[dir + 'ScrollbarWrapper'].style.opacity = hidden && that.options.hideScrollbar ? '0' : '1';
+ that[dir + 'ScrollbarIndicator'].style[transform] = 'translate(' + (dir == 'h' ? pos + 'px,0)' : '0,' + pos + 'px)') + translateZ;
+ },
+
+ _start: function (e) {
+ var that = this,
+ point = hasTouch ? e.touches[0] : e,
+ matrix, x, y,
+ c1, c2;
+
+ if (!that.enabled) return;
+
+ if (that.options.onBeforeScrollStart) that.options.onBeforeScrollStart.call(that, e);
+
+ if (that.options.useTransition || that.options.zoom) that._transitionTime(0);
+
+ that.moved = false;
+ that.animating = false;
+ that.zoomed = false;
+ that.distX = 0;
+ that.distY = 0;
+ that.absDistX = 0;
+ that.absDistY = 0;
+ that.dirX = 0;
+ that.dirY = 0;
+
+ // Gesture start
+ if (that.options.zoom && hasTouch && e.touches.length > 1) {
+ c1 = m.abs(e.touches[0].pageX-e.touches[1].pageX);
+ c2 = m.abs(e.touches[0].pageY-e.touches[1].pageY);
+ that.touchesDistStart = m.sqrt(c1 * c1 + c2 * c2);
+
+ that.originX = m.abs(e.touches[0].pageX + e.touches[1].pageX - that.wrapperOffsetLeft * 2) / 2 - that.x;
+ that.originY = m.abs(e.touches[0].pageY + e.touches[1].pageY - that.wrapperOffsetTop * 2) / 2 - that.y;
+
+ if (that.options.onZoomStart) that.options.onZoomStart.call(that, e);
+ }
+
+ if (that.options.momentum) {
+ if (that.options.useTransform) {
+ // Very lame general purpose alternative to CSSMatrix
+ matrix = getComputedStyle(that.scroller, null)[transform].replace(/[^0-9\-.,]/g, '').split(',');
+ x = matrix[4] * 1;
+ y = matrix[5] * 1;
+ } else {
+ x = getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '') * 1;
+ y = getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '') * 1;
+ }
+
+ if (x != that.x || y != that.y) {
+ if (that.options.useTransition) that._unbind(TRNEND_EV);
+ else cancelFrame(that.aniTime);
+ that.steps = [];
+ that._pos(x, y);
+ }
+ }
+
+ that.absStartX = that.x; // Needed by snap threshold
+ that.absStartY = that.y;
+
+ that.startX = that.x;
+ that.startY = that.y;
+ that.pointX = point.pageX;
+ that.pointY = point.pageY;
+
+ that.startTime = e.timeStamp || Date.now();
+
+ if (that.options.onScrollStart) that.options.onScrollStart.call(that, e);
+
+ that._bind(MOVE_EV);
+ that._bind(END_EV);
+ that._bind(CANCEL_EV);
+ },
+
+ _move: function (e) {
+ var that = this,
+ point = hasTouch ? e.touches[0] : e,
+ deltaX = point.pageX - that.pointX,
+ deltaY = point.pageY - that.pointY,
+ newX = that.x + deltaX,
+ newY = that.y + deltaY,
+ c1, c2, scale,
+ timestamp = e.timeStamp || Date.now();
+
+ if (that.options.onBeforeScrollMove) that.options.onBeforeScrollMove.call(that, e);
+
+ // Zoom
+ if (that.options.zoom && hasTouch && e.touches.length > 1) {
+ c1 = m.abs(e.touches[0].pageX - e.touches[1].pageX);
+ c2 = m.abs(e.touches[0].pageY - e.touches[1].pageY);
+ that.touchesDist = m.sqrt(c1*c1+c2*c2);
+
+ that.zoomed = true;
+
+ scale = 1 / that.touchesDistStart * that.touchesDist * this.scale;
+
+ if (scale < that.options.zoomMin) scale = 0.5 * that.options.zoomMin * Math.pow(2.0, scale / that.options.zoomMin);
+ else if (scale > that.options.zoomMax) scale = 2.0 * that.options.zoomMax * Math.pow(0.5, that.options.zoomMax / scale);
+
+ that.lastScale = scale / this.scale;
+
+ newX = this.originX - this.originX * that.lastScale + this.x,
+ newY = this.originY - this.originY * that.lastScale + this.y;
+
+ this.scroller.style[transform] = 'translate(' + newX + 'px,' + newY + 'px) scale(' + scale + ')' + translateZ;
+
+ if (that.options.onZoom) that.options.onZoom.call(that, e);
+ return;
+ }
+
+ that.pointX = point.pageX;
+ that.pointY = point.pageY;
+
+ // Slow down if outside of the boundaries
+ if (newX > 0 || newX < that.maxScrollX) {
+ newX = that.options.bounce ? that.x + (deltaX / 2) : newX >= 0 || that.maxScrollX >= 0 ? 0 : that.maxScrollX;
+ }
+ if (newY > that.minScrollY || newY < that.maxScrollY) {
+ newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= that.minScrollY || that.maxScrollY >= 0 ? that.minScrollY : that.maxScrollY;
+ }
+
+ that.distX += deltaX;
+ that.distY += deltaY;
+ that.absDistX = m.abs(that.distX);
+ that.absDistY = m.abs(that.distY);
+
+ if (that.absDistX < 6 && that.absDistY < 6) {
+ return;
+ }
+
+ // Lock direction
+ if (that.options.lockDirection) {
+ if (that.absDistX > that.absDistY + 5) {
+ newY = that.y;
+ deltaY = 0;
+ } else if (that.absDistY > that.absDistX + 5) {
+ newX = that.x;
+ deltaX = 0;
+ }
+ }
+
+ that.moved = true;
+ that._pos(newX, newY);
+ that.dirX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
+ that.dirY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;
+
+ if (timestamp - that.startTime > 300) {
+ that.startTime = timestamp;
+ that.startX = that.x;
+ that.startY = that.y;
+ }
+
+ if (that.options.onScrollMove) that.options.onScrollMove.call(that, e);
+ },
+
+ _end: function (e) {
+ if (hasTouch && e.touches.length !== 0) return;
+
+ var that = this,
+ point = hasTouch ? e.changedTouches[0] : e,
+ target, ev,
+ momentumX = { dist:0, time:0 },
+ momentumY = { dist:0, time:0 },
+ duration = (e.timeStamp || Date.now()) - that.startTime,
+ newPosX = that.x,
+ newPosY = that.y,
+ distX, distY,
+ newDuration,
+ snap,
+ scale;
+
+ that._unbind(MOVE_EV);
+ that._unbind(END_EV);
+ that._unbind(CANCEL_EV);
+
+ if (that.options.onBeforeScrollEnd) that.options.onBeforeScrollEnd.call(that, e);
+
+ if (that.zoomed) {
+ scale = that.scale * that.lastScale;
+ scale = Math.max(that.options.zoomMin, scale);
+ scale = Math.min(that.options.zoomMax, scale);
+ that.lastScale = scale / that.scale;
+ that.scale = scale;
+
+ that.x = that.originX - that.originX * that.lastScale + that.x;
+ that.y = that.originY - that.originY * that.lastScale + that.y;
+
+ that.scroller.style[transitionDuration] = '200ms';
+ that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + that.scale + ')' + translateZ;
+
+ that.zoomed = false;
+ that.refresh();
+
+ if (that.options.onZoomEnd) that.options.onZoomEnd.call(that, e);
+ return;
+ }
+
+ if (!that.moved) {
+ if (hasTouch) {
+ if (that.doubleTapTimer && that.options.zoom) {
+ // Double tapped
+ clearTimeout(that.doubleTapTimer);
+ that.doubleTapTimer = null;
+ if (that.options.onZoomStart) that.options.onZoomStart.call(that, e);
+ that.zoom(that.pointX, that.pointY, that.scale == 1 ? that.options.doubleTapZoom : 1);
+ if (that.options.onZoomEnd) {
+ setTimeout(function() {
+ that.options.onZoomEnd.call(that, e);
+ }, 200); // 200 is default zoom duration
+ }
+ } else if (this.options.handleClick) {
+ that.doubleTapTimer = setTimeout(function () {
+ that.doubleTapTimer = null;
+
+ // Find the last touched element
+ target = point.target;
+ while (target.nodeType != 1) target = target.parentNode;
+
+ if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA') {
+ ev = doc.createEvent('MouseEvents');
+ ev.initMouseEvent('click', true, true, e.view, 1,
+ point.screenX, point.screenY, point.clientX, point.clientY,
+ e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
+ 0, null);
+ ev._fake = true;
+ target.dispatchEvent(ev);
+ }
+ }, that.options.zoom ? 250 : 0);
+ }
+ }
+
+ that._resetPos(200);
+
+ if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
+ return;
+ }
+
+ if (duration < 300 && that.options.momentum) {
+ momentumX = newPosX ? that._momentum(newPosX - that.startX, duration, -that.x, that.scrollerW - that.wrapperW + that.x, that.options.bounce ? that.wrapperW : 0) : momentumX;
+ momentumY = newPosY ? that._momentum(newPosY - that.startY, duration, -that.y, (that.maxScrollY < 0 ? that.scrollerH - that.wrapperH + that.y - that.minScrollY : 0), that.options.bounce ? that.wrapperH : 0) : momentumY;
+
+ newPosX = that.x + momentumX.dist;
+ newPosY = that.y + momentumY.dist;
+
+ if ((that.x > 0 && newPosX > 0) || (that.x < that.maxScrollX && newPosX < that.maxScrollX)) momentumX = { dist:0, time:0 };
+ if ((that.y > that.minScrollY && newPosY > that.minScrollY) || (that.y < that.maxScrollY && newPosY < that.maxScrollY)) momentumY = { dist:0, time:0 };
+ }
+
+ if (momentumX.dist || momentumY.dist) {
+ newDuration = m.max(m.max(momentumX.time, momentumY.time), 10);
+
+ // Do we need to snap?
+ if (that.options.snap) {
+ distX = newPosX - that.absStartX;
+ distY = newPosY - that.absStartY;
+ if (m.abs(distX) < that.options.snapThreshold && m.abs(distY) < that.options.snapThreshold) { that.scrollTo(that.absStartX, that.absStartY, 200); }
+ else {
+ snap = that._snap(newPosX, newPosY);
+ newPosX = snap.x;
+ newPosY = snap.y;
+ newDuration = m.max(snap.time, newDuration);
+ }
+ }
+
+ that.scrollTo(m.round(newPosX), m.round(newPosY), newDuration);
+
+ if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
+ return;
+ }
+
+ // Do we need to snap?
+ if (that.options.snap) {
+ distX = newPosX - that.absStartX;
+ distY = newPosY - that.absStartY;
+ if (m.abs(distX) < that.options.snapThreshold && m.abs(distY) < that.options.snapThreshold) that.scrollTo(that.absStartX, that.absStartY, 200);
+ else {
+ snap = that._snap(that.x, that.y);
+ if (snap.x != that.x || snap.y != that.y) that.scrollTo(snap.x, snap.y, snap.time);
+ }
+
+ if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
+ return;
+ }
+
+ that._resetPos(200);
+ if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
+ },
+
+ _resetPos: function (time) {
+ var that = this,
+ resetX = that.x >= 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x,
+ resetY = that.y >= that.minScrollY || that.maxScrollY > 0 ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
+
+ if (resetX == that.x && resetY == that.y) {
+ if (that.moved) {
+ that.moved = false;
+ if (that.options.onScrollEnd) that.options.onScrollEnd.call(that); // Execute custom code on scroll end
+ }
+
+ if (that.hScrollbar && that.options.hideScrollbar) {
+ if (vendor == 'webkit') that.hScrollbarWrapper.style[transitionDelay] = '300ms';
+ that.hScrollbarWrapper.style.opacity = '0';
+ }
+ if (that.vScrollbar && that.options.hideScrollbar) {
+ if (vendor == 'webkit') that.vScrollbarWrapper.style[transitionDelay] = '300ms';
+ that.vScrollbarWrapper.style.opacity = '0';
+ }
+
+ return;
+ }
+
+ that.scrollTo(resetX, resetY, time || 0);
+ },
+
+ _wheel: function (e) {
+ var that = this,
+ wheelDeltaX, wheelDeltaY,
+ deltaX, deltaY,
+ deltaScale;
+
+ if ('wheelDeltaX' in e) {
+ wheelDeltaX = e.wheelDeltaX / 12;
+ wheelDeltaY = e.wheelDeltaY / 12;
+ } else if('wheelDelta' in e) {
+ wheelDeltaX = wheelDeltaY = e.wheelDelta / 12;
+ } else if ('detail' in e) {
+ wheelDeltaX = wheelDeltaY = -e.detail * 3;
+ } else {
+ return;
+ }
+
+ if (that.options.wheelAction == 'zoom') {
+ deltaScale = that.scale * Math.pow(2, 1/3 * (wheelDeltaY ? wheelDeltaY / Math.abs(wheelDeltaY) : 0));
+ if (deltaScale < that.options.zoomMin) deltaScale = that.options.zoomMin;
+ if (deltaScale > that.options.zoomMax) deltaScale = that.options.zoomMax;
+
+ if (deltaScale != that.scale) {
+ if (!that.wheelZoomCount && that.options.onZoomStart) that.options.onZoomStart.call(that, e);
+ that.wheelZoomCount++;
+
+ that.zoom(e.pageX, e.pageY, deltaScale, 400);
+
+ setTimeout(function() {
+ that.wheelZoomCount--;
+ if (!that.wheelZoomCount && that.options.onZoomEnd) that.options.onZoomEnd.call(that, e);
+ }, 400);
+ }
+
+ return;
+ }
+
+ deltaX = that.x + wheelDeltaX;
+ deltaY = that.y + wheelDeltaY;
+
+ if (deltaX > 0) deltaX = 0;
+ else if (deltaX < that.maxScrollX) deltaX = that.maxScrollX;
+
+ if (deltaY > that.minScrollY) deltaY = that.minScrollY;
+ else if (deltaY < that.maxScrollY) deltaY = that.maxScrollY;
+
+ if (that.maxScrollY < 0) {
+ that.scrollTo(deltaX, deltaY, 0);
+ }
+ },
+
+ _mouseout: function (e) {
+ var t = e.relatedTarget;
+
+ if (!t) {
+ this._end(e);
+ return;
+ }
+
+ while (t = t.parentNode) if (t == this.wrapper) return;
+
+ this._end(e);
+ },
+
+ _transitionEnd: function (e) {
+ var that = this;
+
+ if (e.target != that.scroller) return;
+
+ that._unbind(TRNEND_EV);
+
+ that._startAni();
+ },
+
+
+ /**
+ *
+ * Utilities
+ *
+ */
+ _startAni: function () {
+ var that = this,
+ startX = that.x, startY = that.y,
+ startTime = Date.now(),
+ step, easeOut,
+ animate;
+
+ if (that.animating) return;
+
+ if (!that.steps.length) {
+ that._resetPos(400);
+ return;
+ }
+
+ step = that.steps.shift();
+
+ if (step.x == startX && step.y == startY) step.time = 0;
+
+ that.animating = true;
+ that.moved = true;
+
+ if (that.options.useTransition) {
+ that._transitionTime(step.time);
+ that._pos(step.x, step.y);
+ that.animating = false;
+ if (step.time) that._bind(TRNEND_EV);
+ else that._resetPos(0);
+ return;
+ }
+
+ animate = function () {
+ var now = Date.now(),
+ newX, newY;
+
+ if (now >= startTime + step.time) {
+ that._pos(step.x, step.y);
+ that.animating = false;
+ if (that.options.onAnimationEnd) that.options.onAnimationEnd.call(that); // Execute custom code on animation end
+ that._startAni();
+ return;
+ }
+
+ now = (now - startTime) / step.time - 1;
+ easeOut = m.sqrt(1 - now * now);
+ newX = (step.x - startX) * easeOut + startX;
+ newY = (step.y - startY) * easeOut + startY;
+ that._pos(newX, newY);
+ if (that.animating) that.aniTime = nextFrame(animate);
+ };
+
+ animate();
+ },
+
+ _transitionTime: function (time) {
+ time += 'ms';
+ this.scroller.style[transitionDuration] = time;
+ if (this.hScrollbar) this.hScrollbarIndicator.style[transitionDuration] = time;
+ if (this.vScrollbar) this.vScrollbarIndicator.style[transitionDuration] = time;
+ },
+
+ _momentum: function (dist, time, maxDistUpper, maxDistLower, size) {
+ var deceleration = 0.0006,
+ speed = m.abs(dist) / time,
+ newDist = (speed * speed) / (2 * deceleration),
+ newTime = 0, outsideDist = 0;
+
+ // Proportinally reduce speed if we are outside of the boundaries
+ if (dist > 0 && newDist > maxDistUpper) {
+ outsideDist = size / (6 / (newDist / speed * deceleration));
+ maxDistUpper = maxDistUpper + outsideDist;
+ speed = speed * maxDistUpper / newDist;
+ newDist = maxDistUpper;
+ } else if (dist < 0 && newDist > maxDistLower) {
+ outsideDist = size / (6 / (newDist / speed * deceleration));
+ maxDistLower = maxDistLower + outsideDist;
+ speed = speed * maxDistLower / newDist;
+ newDist = maxDistLower;
+ }
+
+ newDist = newDist * (dist < 0 ? -1 : 1);
+ newTime = speed / deceleration;
+
+ return { dist: newDist, time: m.round(newTime) };
+ },
+
+ _offset: function (el) {
+ var left = -el.offsetLeft,
+ top = -el.offsetTop;
+
+ while (el = el.offsetParent) {
+ left -= el.offsetLeft;
+ top -= el.offsetTop;
+ }
+
+ if (el != this.wrapper) {
+ left *= this.scale;
+ top *= this.scale;
+ }
+
+ return { left: left, top: top };
+ },
+
+ _snap: function (x, y) {
+ var that = this,
+ i, l,
+ page, time,
+ sizeX, sizeY;
+
+ // Check page X
+ page = that.pagesX.length - 1;
+ for (i=0, l=that.pagesX.length; i<l; i++) {
+ if (x >= that.pagesX[i]) {
+ page = i;
+ break;
+ }
+ }
+ if (page == that.currPageX && page > 0 && that.dirX < 0) page--;
+ x = that.pagesX[page];
+ sizeX = m.abs(x - that.pagesX[that.currPageX]);
+ sizeX = sizeX ? m.abs(that.x - x) / sizeX * 500 : 0;
+ that.currPageX = page;
+
+ // Check page Y
+ page = that.pagesY.length-1;
+ for (i=0; i<page; i++) {
+ if (y >= that.pagesY[i]) {
+ page = i;
+ break;
+ }
+ }
+ if (page == that.currPageY && page > 0 && that.dirY < 0) page--;
+ y = that.pagesY[page];
+ sizeY = m.abs(y - that.pagesY[that.currPageY]);
+ sizeY = sizeY ? m.abs(that.y - y) / sizeY * 500 : 0;
+ that.currPageY = page;
+
+ // Snap with constant speed (proportional duration)
+ time = m.round(m.max(sizeX, sizeY)) || 200;
+
+ return { x: x, y: y, time: time };
+ },
+
+ _bind: function (type, el, bubble) {
+ (el || this.scroller).addEventListener(type, this, !!bubble);
+ },
+
+ _unbind: function (type, el, bubble) {
+ (el || this.scroller).removeEventListener(type, this, !!bubble);
+ },
+
+
+ /**
+ *
+ * Public methods
+ *
+ */
+ destroy: function () {
+ var that = this;
+
+ that.scroller.style[transform] = '';
+
+ // Remove the scrollbars
+ that.hScrollbar = false;
+ that.vScrollbar = false;
+ that._scrollbar('h');
+ that._scrollbar('v');
+
+ // Remove the event listeners
+ that._unbind(RESIZE_EV, window);
+ that._unbind(START_EV);
+ that._unbind(MOVE_EV);
+ that._unbind(END_EV);
+ that._unbind(CANCEL_EV);
+
+ if (!that.options.hasTouch) {
+ that._unbind('mouseout', that.wrapper);
+ that._unbind(WHEEL_EV);
+ }
+
+ if (that.options.useTransition) that._unbind(TRNEND_EV);
+
+ if (that.options.checkDOMChanges) clearInterval(that.checkDOMTime);
+
+ if (that.options.onDestroy) that.options.onDestroy.call(that);
+ },
+
+ refresh: function () {
+ var that = this,
+ offset,
+ i, l,
+ els,
+ pos = 0,
+ page = 0;
+
+ if (that.scale < that.options.zoomMin) that.scale = that.options.zoomMin;
+ that.wrapperW = that.wrapper.clientWidth || 1;
+ that.wrapperH = that.wrapper.clientHeight || 1;
+
+ that.minScrollY = -that.options.topOffset || 0;
+ that.scrollerW = m.round(that.scroller.offsetWidth * that.scale);
+ that.scrollerH = m.round((that.scroller.offsetHeight + that.minScrollY) * that.scale);
+ that.maxScrollX = that.wrapperW - that.scrollerW;
+ that.maxScrollY = that.wrapperH - that.scrollerH + that.minScrollY;
+ that.dirX = 0;
+ that.dirY = 0;
+
+ if (that.options.onRefresh) that.options.onRefresh.call(that);
+
+ that.hScroll = that.options.hScroll && that.maxScrollX < 0;
+ that.vScroll = that.options.vScroll && (!that.options.bounceLock && !that.hScroll || that.scrollerH > that.wrapperH);
+
+ that.hScrollbar = that.hScroll && that.options.hScrollbar;
+ that.vScrollbar = that.vScroll && that.options.vScrollbar && that.scrollerH > that.wrapperH;
+
+ offset = that._offset(that.wrapper);
+ that.wrapperOffsetLeft = -offset.left;
+ that.wrapperOffsetTop = -offset.top;
+
+ // Prepare snap
+ if (typeof that.options.snap == 'string') {
+ that.pagesX = [];
+ that.pagesY = [];
+ els = that.scroller.querySelectorAll(that.options.snap);
+ for (i=0, l=els.length; i<l; i++) {
+ pos = that._offset(els[i]);
+ pos.left += that.wrapperOffsetLeft;
+ pos.top += that.wrapperOffsetTop;
+ that.pagesX[i] = pos.left < that.maxScrollX ? that.maxScrollX : pos.left * that.scale;
+ that.pagesY[i] = pos.top < that.maxScrollY ? that.maxScrollY : pos.top * that.scale;
+ }
+ } else if (that.options.snap) {
+ that.pagesX = [];
+ while (pos >= that.maxScrollX) {
+ that.pagesX[page] = pos;
+ pos = pos - that.wrapperW;
+ page++;
+ }
+ if (that.maxScrollX%that.wrapperW) that.pagesX[that.pagesX.length] = that.maxScrollX - that.pagesX[that.pagesX.length-1] + that.pagesX[that.pagesX.length-1];
+
+ pos = 0;
+ page = 0;
+ that.pagesY = [];
+ while (pos >= that.maxScrollY) {
+ that.pagesY[page] = pos;
+ pos = pos - that.wrapperH;
+ page++;
+ }
+ if (that.maxScrollY%that.wrapperH) that.pagesY[that.pagesY.length] = that.maxScrollY - that.pagesY[that.pagesY.length-1] + that.pagesY[that.pagesY.length-1];
+ }
+
+ // Prepare the scrollbars
+ that._scrollbar('h');
+ that._scrollbar('v');
+
+ if (!that.zoomed) {
+ that.scroller.style[transitionDuration] = '0';
+ that._resetPos(200);
+ }
+ },
+
+ scrollTo: function (x, y, time, relative) {
+ var that = this,
+ step = x,
+ i, l;
+
+ that.stop();
+
+ if (!step.length) step = [{ x: x, y: y, time: time, relative: relative }];
+
+ for (i=0, l=step.length; i<l; i++) {
+ if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; }
+ that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 });
+ }
+
+ that._startAni();
+ },
+
+ scrollToElement: function (el, time) {
+ var that = this, pos;
+ el = el.nodeType ? el : that.scroller.querySelector(el);
+ if (!el) return;
+
+ pos = that._offset(el);
+ pos.left += that.wrapperOffsetLeft;
+ pos.top += that.wrapperOffsetTop;
+
+ pos.left = pos.left > 0 ? 0 : pos.left < that.maxScrollX ? that.maxScrollX : pos.left;
+ pos.top = pos.top > that.minScrollY ? that.minScrollY : pos.top < that.maxScrollY ? that.maxScrollY : pos.top;
+ time = time === undefined ? m.max(m.abs(pos.left)*2, m.abs(pos.top)*2) : time;
+
+ that.scrollTo(pos.left, pos.top, time);
+ },
+
+ scrollToPage: function (pageX, pageY, time) {
+ var that = this, x, y;
+
+ time = time === undefined ? 400 : time;
+
+ if (that.options.onScrollStart) that.options.onScrollStart.call(that);
+
+ if (that.options.snap) {
+ pageX = pageX == 'next' ? that.currPageX+1 : pageX == 'prev' ? that.currPageX-1 : pageX;
+ pageY = pageY == 'next' ? that.currPageY+1 : pageY == 'prev' ? that.currPageY-1 : pageY;
+
+ pageX = pageX < 0 ? 0 : pageX > that.pagesX.length-1 ? that.pagesX.length-1 : pageX;
+ pageY = pageY < 0 ? 0 : pageY > that.pagesY.length-1 ? that.pagesY.length-1 : pageY;
+
+ that.currPageX = pageX;
+ that.currPageY = pageY;
+ x = that.pagesX[pageX];
+ y = that.pagesY[pageY];
+ } else {
+ x = -that.wrapperW * pageX;
+ y = -that.wrapperH * pageY;
+ if (x < that.maxScrollX) x = that.maxScrollX;
+ if (y < that.maxScrollY) y = that.maxScrollY;
+ }
+
+ that.scrollTo(x, y, time);
+ },
+
+ disable: function () {
+ this.stop();
+ this._resetPos(0);
+ this.enabled = false;
+
+ // If disabled after touchstart we make sure that there are no left over events
+ this._unbind(MOVE_EV);
+ this._unbind(END_EV);
+ this._unbind(CANCEL_EV);
+ },
+
+ enable: function () {
+ this.enabled = true;
+ },
+
+ stop: function () {
+ if (this.options.useTransition) this._unbind(TRNEND_EV);
+ else cancelFrame(this.aniTime);
+ this.steps = [];
+ this.moved = false;
+ this.animating = false;
+ },
+
+ zoom: function (x, y, scale, time) {
+ var that = this,
+ relScale = scale / that.scale;
+
+ if (!that.options.useTransform) return;
+
+ that.zoomed = true;
+ time = time === undefined ? 200 : time;
+ x = x - that.wrapperOffsetLeft - that.x;
+ y = y - that.wrapperOffsetTop - that.y;
+ that.x = x - x * relScale + that.x;
+ that.y = y - y * relScale + that.y;
+
+ that.scale = scale;
+ that.refresh();
+
+ that.x = that.x > 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x;
+ that.y = that.y > that.minScrollY ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
+
+ that.scroller.style[transitionDuration] = time + 'ms';
+ that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + scale + ')' + translateZ;
+ that.zoomed = false;
+ },
+
+ isReady: function () {
+ return !this.moved && !this.zoomed && !this.animating;
+ }
+};
+
+function prefixStyle (style) {
+ if ( vendor === '' ) return style;
+
+ style = style.charAt(0).toUpperCase() + style.substr(1);
+ return vendor + style;
+}
+
+dummyStyle = null; // for the sake of it
+
+if (typeof exports !== 'undefined') exports.iScroll = iScroll;
+else window.iScroll = iScroll;
+
+})(this, document);
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/itablet.js b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/itablet.js
new file mode 100644
index 0000000000..33f01241df
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/itablet.js
@@ -0,0 +1,1492 @@
+/**
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This library implements a general user interface look and feel similar to a "well know tablet PC" :-)
+ * It provides animated page transition eye-candy but is, in essence, really just a fancy tabbed window.
+ *
+ * It has dependencies on the following:
+ * itablet.css
+ * iscroll.js
+ * jquery.js (jquery-1.7.1.min.js)
+ *
+ * author Fraser Adams
+ */
+
+/**
+ * Create a Singleton instance of the iTablet user interface generic look and feel.
+ */
+var iTablet = new function() {
+ if (!String.prototype.trim) { // Add a String trim method if one doesn't exist (modern browsers should have it.)
+ String.prototype.trim = function() {
+ return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
+ };
+ }
+
+ /**
+ * The Location inner class allows iTablet.location to be used similarly to window.location.
+ */
+ var Location = function(href) {
+ this.href = href;
+ var split = href.split("?"); // Split string by query part.
+ this.hash = split[0];
+ this.search = split.length == 2 ? "?" + split[1] : "";
+ this.data = null;
+
+ // Populate the data property with key/value pairs extracted from search part of URL.
+ if (split.length == 2) {
+ this.data = {};
+ var kv = split[1].split("&"); // Split string into key/value pairs using the & is the separator.
+ var length = kv.length;
+ for (var i = 0; i < length; i++) {
+ var s = kv[i].split("=");
+ if (s.length == 2) {
+ var key = s[0].trim();
+ var value = s[1].trim();
+ this.data[key] = value;
+ }
+ }
+ }
+
+ Location.prototype.toString = function() {
+ return this.href;
+ };
+
+ // Location.back() is mapped to the iTablet.goBack() method.
+ // This allows clients to explicitly return to a previous page, useful for coding submit handlers etc.
+ Location.prototype.back = goBack;
+ };
+
+ /**
+ * The TextChange inner class adds support for a textchange Event on text input and textarea tags.
+ * Initialise with: $.event.special.textchange = new TextChange();
+ * Uses info derived from from http://benalman.com/news/2010/03/jquery-special-events/
+ */
+ var TextChange = function() {
+ /**
+ * Directly call the triggerIfChanged method on keyup.
+ */
+ var handler = function() {
+ triggerIfChanged(this);
+ };
+
+ /**
+ * For cut, paste and input handlers we need to call triggerIfChanged from a timeout.
+ */
+ var handlerWithDelay = function() {
+ var element = this;
+ setTimeout(function() {
+ triggerIfChanged(element);
+ }, 25);
+ };
+
+ /**
+ * Trigger textchange Event handler bound to target element if the text has changed.
+ */
+ var triggerIfChanged = function(domElement) {
+ var element = $(domElement);
+ var current = domElement.contentEditable === "true" ? element.html() : element.val();
+ if (current !== element.data("lastValue")) {
+ element.trigger("textchange", [element.data("lastValue")]);
+ element.data("lastValue", current);
+ }
+ };
+
+ /**
+ * Called by jQuery when the first event handler is bound to a particular element.
+ */
+ this.setup = function(data) {
+ var jthis = $(this);
+ jthis.data("lastValue", this.contentEditable === 'true' ? jthis.html() : jthis.val());
+ // Bind keyup, cut, paste and input handlers in the .textchange Event namespace to allow easy unbinding.
+ jthis.bind("keyup.textchange", handler);
+ jthis.bind("cut.textchange paste.textchange input.textchange", handlerWithDelay);
+ };
+
+ /**
+ * Called by jQuery when the last event handler is unbound from a particular element.
+ */
+ this.teardown = function (data) {
+ $(this).unbind('.textchange'); // Unbind the Events linked to the .textchange Event namespace.
+ }
+ };
+
+//-------------------------------------------------------------------------------------------------------------------
+
+ var TOUCH_ENABLED = 'ontouchstart' in window && !((/hp-tablet/gi).test(navigator.appVersion));
+
+ // Select start, move and end events based on whether or not the user agent is a touch device.
+ var START_EV = (TOUCH_ENABLED) ? "touchstart" : "mousedown";
+ var MOVE_EV = (TOUCH_ENABLED) ? "touchmove" : "mousemove";
+ var END_EV = (TOUCH_ENABLED) ? "touchend" : "mouseup";
+
+ // Populated in initialiseCSSAnimations()
+ var ANIMATION_END_EV = "";// = "animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd";
+ var TRANSITION_END_EV = "";//"transitionend webkitTransitionEnd MSTransitionEnd oTransitionEnd";
+
+ /**
+ * The general perceived wisdom is to use feature detection rather than browser sniffing, which seems a good
+ * aim, but as it happens *most* of the browser abstraction is happening in jQuery and CSS but there remain
+ * a few quirks, mostly for IE < 9. IE < 9 and Opera < 12 both appear not to trigger a change when radio or
+ * checkbox state changes and it's not clear how to "feature detect" this, which is the main reason for
+ * including the Opera version sniffing.
+ */
+ var IS_IE = (navigator.appName == "Microsoft Internet Explorer");
+ var IE_VERSION = IS_IE ? /MSIE (\d+)/.exec(navigator.userAgent)[1] : 1000000;
+ var IS_OPERA = (navigator.appName == "Opera") && (window.opera.version != null);
+ var OPERA_VERSION = IS_OPERA ? opera.version() : 1000000;
+
+ var BODY; // jQuery object for body is used in several places so let's cache it (gets set in jQuery.ready()).
+ var IS_MOBILE = false; // Gets set if we detect a small display (e.g. mobile) device.
+
+ var _mainLeft = 0; // N.B. We need to get the actual value after the DOM has loaded.
+ var _history = []; // URL history to enable back button behaviour.
+ var _scrollers = {};
+ var _transitions = {}; // Map of transition names to transition functions (populate later after functions defined).
+ this.location = null;
+
+ /**
+ * This public helper method renders an HTML list with up to <maxlength> list items using the <contents> function.
+ * If the length of the list is less than the number added by the contents function additional list items are
+ * appended, conversely if the length of the list is greater than the number added by the contents function then
+ * the list is truncated.
+ *
+ * The contents of the list are populated via the supplied <contents> function, which should take an index as a
+ * parameter and return an <li> with contents or false. If false is returned that item is skipped.
+ * If an HTML list is supplied without a maxlength and contents function this method will simply carry out
+ * reskinning of the input widgets for the supplied list (and adding radiused borders for older versions of IE).
+ *
+ * For some reason this method seems to run very sluggishly on IE6, is's especially noticable when doing a
+ * resize. It runs fine on every other browser. I've not noticed any obvious inefficiencies but IE6 is weird..
+ *
+ * @param list jQuery object representing the html list (ul) we wish to populate.
+ * @param maxlength the maximum number of items that we wish to populate.
+ * @param contents a function to populate the list contents, this function should take an index as a parameter.
+ * and return an <li> with the required contents or false to skip (useful if filtering is needed).
+ */
+ this.renderList = function(list, contents, maxlength) {
+ // For IE 6 get the width. Have to use .main or .popup-container because list.innerWidth() may not be set yet.
+ var listWidth = 0;
+
+ if (IE_VERSION < 7) { // This seems to be very slow on IE6, no idea why???
+ var main = list.closest(".main");
+ if (main.length == 0) { // It's a list in a popup
+ listWidth = Math.round(parseInt($(".popup-container").css('width'), 10) * 0.9);
+ } else {
+ listWidth = Math.round($(".main").width() * 0.9);
+ }
+ }
+
+ var lengthChanged = false;
+ var items = list.children("li");
+
+ if (contents == null) {
+ maxlength = items.length;
+ } else if (maxlength == null) {
+ maxlength = 1; // If no maxlength is supplied default to calling the contents function once.
+ }
+
+ var actualLength = 0; // Actual number of <li> supplied, this caters for the contents function returning false.
+ for (var i = 0; i < maxlength; i++) {
+ var li = false;
+ if (actualLength < items.length) {
+ if (contents) { // Modify list item with the new contents at index i.
+ var newItem = contents(i);
+ if (newItem) { // If the contents function didn't return false add contents to current li.
+ li = $(items[actualLength]);
+ actualLength++;
+ var active = li.hasClass("active") ? "active" : "";
+ var newItem = $(newItem).addClass(active);
+ li.removeClass().addClass(newItem.attr("class")); // Remove existing classes and add new ones.
+ li.html(newItem.html());
+ }
+ } else { // If contents function not present we simply reskin the current list item.
+ li = $(items[actualLength]);
+ actualLength++;
+
+ if (IE_VERSION < 9) {
+ // Remove any markup used for faking :first-child, :last-child, :before, :after
+ li.removeClass("first-child last-child");
+ li.children("div.before, div.after, div.fbefore, div.fafter").remove();
+ }
+ }
+ } else { // If there are fewer items in the list than there are contents then append new list items.
+ var newItem = contents(i);
+ if (newItem) { // If the contents function didn't return false append contents as new li.
+ li = $(newItem);
+ actualLength++;
+ list.append(li);
+ lengthChanged = true;
+ }
+ }
+
+ if (li) {
+ // Reskin input widgets.
+ Radio.reskin(li.children("input:radio"));
+ Checkbox.reskin(li.children("input:checkbox"));
+
+ // Fix several quirks in early versions of IE.
+ if (IE_VERSION < 8) {
+ var anchor = li.children("a");
+ anchor.attr("hideFocus", "hidefocus"); // Fix lack of outline: none; in IE < 8
+
+ if (IE_VERSION < 7) { // IE6 percentage widths are messed up so need to set absolute width.
+ // 41 comes from padding: 0 30px 0 11px; 22 comes from padding: 0 11px 0 11px;
+ // 34 comes from margin-left: 5px; text-indent: 40px; minus 11.
+ var anchorWidth = listWidth - ((li.hasClass("arrow") ? 41 : 22) +
+ (anchor.hasClass("icon") ? 34 : 11));
+ anchor.css({"width": anchorWidth + "px"});
+
+ // IE6 can't cope with multiple CSS classes so we need to merge these into a single class.
+ if (li.is(".arrow.radio")) {
+ li.addClass("ie6-radio-arrow");
+ if (li.hasClass("checked")) {
+ li.addClass("ie6-checked-arrow");
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // If list is longer than the contents being added then trim the list so it's the same size.
+ if (actualLength < items.length) {
+ items.slice(actualLength).remove();
+ lengthChanged = true;
+ }
+
+ // Add radiused borders for IE8 and below.
+ // We have to do this after completely populating the list so first() and last() are correct.
+ if (IE_VERSION < 9) {
+ items = list.children("li");
+ var last = items.last();
+ last.addClass("last-child").prepend("<div class='before'></div>").append("<div class='after'></div>");
+
+ if (IE_VERSION < 8) {
+ var first = items.first();
+ if (IE_VERSION == 7) { // For IE7 fake :first-child:before and :first-child:after
+ first.prepend("<div class='fbefore'></div>").append("<div class='fafter'></div>");
+ } else if (IE_VERSION < 7) { // For IE6 fake :first-child
+ // We're not adding radiused borders to IE6, this class provides the proper top border colour.
+ first.addClass("first-child");
+ }
+ }
+ }
+
+ // If the length has changed trigger an iScroll refresh on the top level page that contains the list.
+ if (lengthChanged) {
+ list.closest(".main").trigger("refresh"); // refresh is a synthetic event handled by parents of scroll-area
+ }
+ };
+
+//-------------------------------------------------------------------------------------------------------------------
+// UI Widgets
+//-------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Create a Singleton instance of the Radio class used to reskin and manage HTML input type="radio" widgets.
+ */
+ var Radio = new function() {
+ /**
+ * "Reskin" HTML input type="radio" items into a tablet "tick" style radio item. Note that the radio item
+ * needs to have a label sibling and be wrapped in a parent <li> for this to work correctly.
+ * e.g. <ul class="list"><li><label>test</label><input type="radio" name="test-radio" checked /></li></ul>
+ */
+ this.reskin = function(radios) {
+ if (radios == null) { // if no input:radio is specified attempt to reskin every one in the document.
+ radios = $("input:radio");
+ }
+
+ // Add classes to container <li> based on "template" radio buttons. This "re-skins" the radio buttons.
+ radios.each(function() { // Iterate through each radio button.
+ var jthis = $(this).hide();
+ if (!jthis.hasClass("reskinned")) { // If checkbox has already been reskinned move on.
+ var parent = jthis.parent();
+ parent.addClass("radio");
+ if (this.checked) {
+ parent.addClass("checked");
+ }
+ jthis.addClass("reskinned"); // Mark as reskinned to avoid trying to reskin it again.
+ }
+ });
+ };
+
+ /**
+ * Handle radio button state changes. This method is delegated to by the main handlePointer end() method.
+ * Note that we are actually passing in the $("ul li.radio") jQuery object that the Event was bound to
+ * rather than the actual Event object as this has already been extracted by handlePointer and is more
+ * useful for the implementation of this method.
+ */
+ this.handleClick = function(jthis, type) {
+ var checked = jthis.parent().children(".checked");
+ var radio = jthis.children("input:radio"); // Select the template radio button.
+
+ fade(jthis); // Fade out the highlighting of the selected <li>
+
+ if (type != "click") { // If this handler wasn't triggered by a radio button click we synthesise one.
+ BODY.unbind("click", handlePointer); // Prevent the synthetic click from triggering handlePointer.
+ radio.click(); // Trigger radio button's click (on modern browsers this triggers change too if changed).
+ BODY.click(handlePointer);
+ }
+
+ // We explicitly manipulate input:radio checked attr in the following block in case a name attr wasn't
+ // specified in the HTML. With reskinned radio buttons the parent <ul> is the real container.
+ if (!jthis.is(checked)) { // If the clicked item is not the previously checked item.
+ // Clear any check mark on the previously selected <li> and the same on the template radio button.
+ checked.removeClass("checked");
+ checked.children("input:radio").attr("checked", false);
+
+ // Mark the current <li> as checked and do the same on the template radio button.
+ jthis.addClass("checked").change();
+ jthis.children("input:radio").attr("checked", true);
+
+ // For older IE/Opera triggering the click as done earlier won't trigger the change event so do it now.
+ if (IE_VERSION < 9 || OPERA_VERSION < 12) {
+ radio.change();
+ }
+ }
+ };
+ };
+
+ /**
+ * Create a Singleton instance of the Checkbox class used to reskin and manage HTML input type="checkbox" widgets.
+ */
+ var Checkbox = new function() {
+ /**
+ * Return the input element associated with the specified label. This is used because the input element
+ * may be associated to the label in a number of different was (via the "for" attribute, by containment etc.)
+ */
+ var findInputElement = function(label) {
+ var input = $("#" + label.attr("for")); // First check if label for points to the input.
+ if (input.length == 0) { // If not check if the label contains the input.
+ input = label.children("input");
+ }
+ if (input.length == 0) { // Finally check if the label's next sibling is an input.
+ input = label.next("input");
+ }
+
+ return input;
+ };
+
+ /**
+ * "Reskin" HTML input type="checkbox" items into a tablet "switch" style checkbox. Note that the checkbox
+ * needs to have a label sibling and be wrapped in a parent <li> for this to work correctly.
+ * e.g. <ul class="list"><li><label>test</label><input type="checkbox" name="test-checkbox" checked /></li></ul>
+ * If multiple <input type="checkbox"> elements are placed in an <li> then they will automatically be
+ * reskinned as a "horiz-checkbox", this can also be done explicitly by doing <li class="horiz-checkbox">
+ */
+ this.reskin = function(checkboxes) {
+ if (checkboxes == null) { // if no input:checkbox is specified attempt to reskin every one in the document.
+ checkboxes = $("input:checkbox");
+ }
+
+ checkboxes.each(function() { // Iterate through each checkbox.
+ var jthis = $(this).hide();
+ if (!jthis.hasClass("reskinned")) { // If checkbox has already been reskinned move on.
+ // If there are multiple checkboxes in a container create a horizontal checkbox by adding class
+ // to parent. Note that <li class="horiz-checkbox"> may also be explicitly set in the HTML.
+ jthis.siblings("input:checkbox").parent().addClass("horiz-checkbox");
+
+ // Mop up where checkbox is contained by label e.g. <label>test<input type="checkbox"/></label>
+ jthis.parent().siblings("label").parent().addClass("horiz-checkbox");
+
+ var li = jthis.closest("li"); // Find containing li.
+
+ if (li.hasClass("horiz-checkbox")) { // Reskin horizontal checkbox.
+ // IE8 doesn't seem to distinguish between the selectors ul.list li:first-child:before and
+ // ul.list li.horiz-checkbox:first-child:before when horiz-checkbox is dynamically added
+ // this stops the <li> fake radiused border being correctly positioned for horiz-checkboxes.
+ // By adding horiz-checkbox class to the <ul> too we can use a more explicit rule in the CSS.
+ li.parent().addClass("horiz-checkbox");
+
+ // As we use inline-block for horiz-checkbox we need to remove any whitespace text nodes.
+ li.contents().filter(function() {
+ return (this.nodeType == 3 && $.trim($(this).text()).length == 0);
+ }).remove();
+
+ // For horiz-checkbox we set the width of each item and add a span containing the right border.
+ // The inner span is needed so the border doesn't impact the element width calculation.
+ li.each(function() {
+ var buttons = $(this).children("label");
+ var width = 100/buttons.length;
+
+ buttons.css("width", width + "%"); // Using the percentage works for browsers > IE7.
+ // The child span helps position the border - see css (ul.list li.horiz-checkbox label span)
+ buttons.filter(":not(:last)").append("<span></span>");
+ buttons.first().addClass("first-child");
+ buttons.last().addClass("last-child");
+
+ // Early IE doesn't respect the width so reduce the width of the last item a little.
+ if (width < 100 && (IE_VERSION < 8 )) {
+ buttons.last().css("width", width - 1 + "%")
+ }
+
+ // Find input associated with each label and if it's checked add "checked" class to label.
+ buttons.each(function() {
+ var button = $(this);
+ var input = findInputElement(button);
+ input.addClass("reskinned"); // Mark as reskinned to avoid trying to reskin it again.
+ if (input.attr("checked")) {
+ button.addClass("checked");
+ if (button.is(buttons.last())) {
+ // Use toggle-on not checked to avoid confusing IE6.
+ button.parent().addClass("toggle-on");
+ }
+ }
+ });
+ });
+ } else { // Reskin normal checkbox.
+ // Add markup to container <li> based on "template" checkboxes. This "re-skins" the checkboxes.
+ jthis.parent().
+ append("<div class='checkbox'><div class='mask'></div><div class='onoff'></div></div>");
+
+ // If the checkbox is checked find onoff switch and change its initial position to "on".
+ jthis.filter(":checked").siblings(".checkbox").children(".onoff").css("left", "0px");
+ jthis.addClass("reskinned"); // Mark as reskinned to avoid trying to reskin it again.
+ }
+ }
+ });
+ };
+
+ /**
+ * Handle checkbox state changes. This method is delegated to by the main handlePointer method.
+ */
+ this.handlePointer = function(e, type) {
+ // If triggered by a synthetic click the target is an input:checkbox otherwise it's a div.mask
+ var jthis = (type == "click") ? $(e.target).siblings("div.checkbox") : $(e.target).parent();
+ var onoff = jthis.children(".onoff");
+ var checkbox = jthis.parent().children("input:checkbox"); // Select the underlying <input type="checkbox">
+ var offsetX = onoff.offset().left - jthis.offset().left;
+ var offset = -parseInt(onoff.css("left"), 10); // If we use translate we adjust by the left CSS position.
+ var startX = (e.pageX != null) ? e.pageX : e.originalEvent.targetTouches[0].pageX;
+ var clicked = true; // Set to false if move handler is called;
+
+ var move = function(e) {
+ var newX = (e.pageX != null) ? e.pageX : e.originalEvent.changedTouches[0].pageX;
+ var diffX = offsetX + newX - startX;
+ clicked = false;
+
+ if (diffX >= -50 && diffX <= 0) {
+ setPosition(onoff, offset, diffX);
+ }
+ e.stopPropagation(); // Prevent iScroll from trying to scroll when we drag the switch.
+ };
+
+ /**
+ * The pointer up handler is only bound when the pointer down has been triggered and so behaves like a click.
+ */
+ var end = function(e) {
+ var pos = onoff.offset().left - jthis.offset().left;
+ var duration = 300;
+
+ if (clicked) {
+ pos = (pos == 0) ? -50 : 0;
+ } else {
+ // Animation duration is between 150ms and 0ms based on position.
+ duration = (25 - Math.abs(pos + 25)) * 6;
+ pos = (pos < -25) ? -50 : 0;
+
+ }
+
+ setPosition(onoff, offset, pos, duration);
+
+ BODY.unbind("click", handlePointer); // Prevent the synthetic click from triggering handlePointer.
+ var currentlyChecked = checkbox[0].checked;
+ if ((currentlyChecked && pos == -50) || (!currentlyChecked && pos == 0)) {
+ if (type == "click") {
+ checkbox.attr("checked", !currentlyChecked);
+ } else {
+ checkbox.click();
+ // For older IE/Opera triggering the click won't trigger the change event so do it now.
+ if (IE_VERSION < 9 || OPERA_VERSION < 12) {
+ checkbox.change();
+ }
+ }
+ }
+ BODY.click(handlePointer);
+
+ if (TOUCH_ENABLED) {
+ jthis.unbind(MOVE_EV + " " + END_EV);
+ } else {
+ BODY.unbind(MOVE_EV + " " + END_EV + " mouseleave");
+ }
+ };
+
+ if (type == "click") {
+ end(e);
+ } else {
+ // Bind move, end and mouseleave events to our internal handlers.
+ if (TOUCH_ENABLED) { // Touch events track over the whole page by default.
+ jthis.bind(MOVE_EV, move).bind(END_EV, end);
+ } else { // Bind mouse events to body so we can track them over the whole page.
+ BODY.bind(MOVE_EV, move).bind(END_EV + " mouseleave", end);
+ }
+ }
+ };
+
+ /**
+ * Handle horiz-checkbox state changes. This method is delegated to by the main handlePointer end() method.
+ * Note that we are actually passing in the $("ul li.horiz-checkbox label") jQuery object that the Event was
+ * bound to rather than the actual Event object as this has already been extracted by handlePointer and is
+ * more useful for the implementation of this method.
+ */
+ this.handleClick = function(jthis, type) {
+ var parent = jthis.parent();
+ var lastChild = parent.children("label").last();
+
+ if (jthis.hasClass("checked")) {
+ jthis.removeClass("checked");
+ if (jthis.is(lastChild)) {
+ parent.removeClass("toggle-on"); // Use toggle-on rather than checked to avoid confusing IE6.
+ }
+ } else {
+ jthis.addClass("checked");
+ if (jthis.is(lastChild)) {
+ parent.addClass("toggle-on"); // Use toggle-on rather than checked to avoid confusing IE6.
+ }
+ }
+
+ if (type == "click") {
+ var input = findInputElement(jthis);
+ input.attr("checked", !input.attr("checked"));
+ } else { // If this handler wasn't triggered by a checkbox click we synthesise one.
+ BODY.unbind("click", handlePointer); // Prevent the synthetic click from triggering handlePointer.
+ var checkbox = findInputElement(jthis);
+ checkbox.click();
+ // For older IE/Opera triggering the click won't trigger the change event so do it now.
+ if (IE_VERSION < 9 || OPERA_VERSION < 9) {
+ checkbox.change();
+ }
+ BODY.click(handlePointer);
+ }
+ }
+ };
+
+//-------------------------------------------------------------------------------------------------------------------
+// Main Event Handler
+//-------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * This method handles the pointer down, move and up events.
+ * We handle the discrete events because mobile Safari adds a 300ms delay to the click handler, in addition
+ * we want to be able to un-highlight rows if we move the mouse/finger. Note that this handler is in the form
+ * of a delegating event handler - we actually bind the events to the html body, this is so that if we modify
+ * the DOM externally, e.g. via an AJAX update we will trigger from newly created elements too.
+ * Note that the start(), removeHighlight(), resetHighlight(), touchMove() and end() methods are private.
+ * This method does actually handle click events but its main job is to prevent the default navigation action
+ * on href, however if the click event is a synthetic click caused by a jQuery trigger the method behaves like
+ * a proper click handler.
+ */
+ var handlePointer = function(e) {
+ // These are the *actual* selectors that we are interested in handling events for.
+ var selectors = "ul.contents li, ul.mail li, ul li.radio, ul li div.checkbox, ul li.horiz-checkbox label, " +
+ "ul li.arrow, ul li.pop, div.header a.back, div.header a.done, div.header a.cancel, " +
+ "div.header a.menu";
+
+ var target = e.target;
+ var jthis = $(target);
+ var parent;
+ var prev;
+ var href = jthis.attr("href");
+ var chevronClicked = false; // Set true if we've clicked on a chevron (used for navigable radio buttons).
+ var scrolled; // Gets set if a page has been (touch) scrolled.
+ var highlighted; // Gets set if a sidebar or mail item has been selected/highlighted.
+ var startY; // The vertical position when a touchstart gets triggered.
+
+ var start = function(e) {
+ // This block checks if the event target is one of the selectors, if not it uses jQuery closest to get the
+ // first element that matches the selector, start at the current element and progress up through the DOM.
+ if (!jthis.is(selectors)) {
+ jthis = jthis.closest(selectors);
+ }
+
+ // If closest object doesn't match any of the selectors return true if it has an href else return false.
+ if (jthis.length == 0) {
+ return (!!href); // The href test allows the browser to add the active pseudoclass.
+ }
+
+ if (jthis.hasClass("checkbox")) { // If a checkbox then delegate to the Checkbox handlePointer() handler.
+ Checkbox.handlePointer(e);
+ return false;
+ }
+
+ parent = jthis.parent();
+
+ // prev is the previously highlighted item. We search from parent's parent as we may have multiple lists.
+ prev = parent.parent().find(".active");
+
+ href = jthis.attr("href"); // Get the href of the element matching the selector.
+
+ var TOUCHED_SIDEBAR = TOUCH_ENABLED && parent.is(".contents, .mail"); // Is this a touch on a sidebar list?
+
+ // If the href isn't directly present then it's an <li> that contains the anchor, so we have to look further.
+ if (!href) {
+ var ICON_WIDTH = 45; // The width of the icon image plus some padding.
+ var offset = Math.ceil(jthis.offset().left);
+
+ // Get the pointer x value relative to the <li>
+ var x = (e.pageX != null) ? e.pageX - offset : // Mouse position.
+ (e.originalEvent != null) ? e.originalEvent.targetTouches[0].pageX - offset : 0; // Touch pos.
+
+ // If target is a clickable-icon we return immediately thus preventing any highlighting or navigation.
+ if (jthis.hasClass("clickable-icon") && (x < ICON_WIDTH)) {
+ return false;
+ }
+
+ // If target is a navigable radio button then check if chevron was clicked/tapped.
+ if (jthis.hasClass("radio") && jthis.hasClass("arrow") && ((jthis.outerWidth() - x) < ICON_WIDTH)) {
+ chevronClicked = true;
+ }
+
+ e.preventDefault(); // Stop the anchor default highlighting, we'll add our own prettier highlight.
+
+ // This block highlights the selected <li> on mousedown or touchstart. For touch enabled devices we wait
+ // for a short time before highlighting in case the touchstart was the start of a scroll rather than a
+ // selection. If it was a scroll then the scrolled flag will get set by the touchMove handler and the
+ // highlight is aborted when the timeout gets triggered.
+ if (!prev[0] || prev[0] != jthis[0]) {
+ if (TOUCHED_SIDEBAR && !IS_MOBILE) {
+ // If TOUCH_ENABLED and a sidebar or mail list wait 50ms before highlighting in case the
+ // touch start is really the start of a touch scroll event.
+ scrolled = false;
+ highlighted = false;
+
+ setTimeout(function() {
+ if (!scrolled) { // scrolled may be set by touchMove if the list has been scrolled.
+ prev.removeClass("active");
+ jthis.addClass("active"); // Highlight the current <li>
+ highlighted = true;
+ }
+ }, 50);
+ } else { // If not TOUCH_ENABLED or a sidebar or mail list highlight immediately.
+ prev.removeClass("active");
+ // Navigable radio buttons don't highlight when the chevron is clicked.
+ if (!chevronClicked) {
+ jthis.addClass("active"); // Highlight the current <li>
+ }
+ }
+ }
+
+ href = jthis.children("a:first").attr("href"); // Get the href from the first anchor enclosed by the <li>
+ href = (href == null) ? "#" : href; // Create default href of "#" if none has been specified.
+ href = href.replace(window.location, ""); // Fix "absolute href" bug found in IE7 and below.
+ }
+
+ BODY.bind(END_EV, end).unbind(START_EV, handlePointer);
+
+ if (parent.hasClass("list") || (TOUCHED_SIDEBAR && IS_MOBILE)) {
+ // For a small (e.g. mobile) displays the sidebar becomes the main menu page and touches behave
+ // like normal list touches and become inactive on any touch move.
+ BODY.bind(MOVE_EV, removeHighlight);
+ } else if (TOUCHED_SIDEBAR && !IS_MOBILE) {
+ // For a real sidebar detect touch scrolling on these items.
+ startY = (e.originalEvent) ? e.originalEvent.targetTouches[0].pageY : 0;
+ BODY.bind(MOVE_EV, touchMove);
+ }
+ };
+
+ /**
+ * If we move the mouse or finger in a list item we un-highlight and deactivate.
+ */
+ var removeHighlight = function(e) {
+ BODY.unbind(MOVE_EV + " " + END_EV).bind(START_EV, handlePointer);
+ jthis.removeClass("active");
+ };
+
+ /**
+ * If we move a finger up or down in a sidebar item we reinstate the previous highlight ontouchend.
+ */
+ var resetHighlight = function(e) {
+ BODY.unbind(END_EV).bind(START_EV, handlePointer);
+ prev.addClass("active");
+ };
+
+ /**
+ * This touch move handler is only bound if the initial event is a touch start event bound to a <li>
+ * with a <ul> parent that has a .contents or .mail class. These lists need to be touch scrollable, but
+ * they also need to have a persistent highlight on selected items. This method checks how many vertical
+ * pixels have been scrolled and if it exceeds a threshold it triggers a scrolled state. Once scrolled it removes
+ * any new highlighting and binds resetHighlight to touchend, which reinstates the previous highlight.
+ */
+ var touchMove = function(e) {
+ var newY = e.originalEvent.changedTouches[0].pageY;
+ if (Math.abs(newY - startY) > 7) { // Only trigger on an up/down finger movement.
+ if (highlighted) { // If a new item was highlighted set the highlighting back to the previous item.
+ BODY.unbind(MOVE_EV + " " + END_EV).bind(END_EV, resetHighlight);
+ } else {
+ BODY.unbind(MOVE_EV + " " + END_EV).bind(START_EV, handlePointer);
+ }
+
+ if (prev[0] != jthis[0]) {
+ jthis.removeClass("active");
+ }
+ scrolled = true;
+ }
+ };
+
+ /**
+ * The pointer up handler is only bound when the pointer down has been triggered and so behaves like a click
+ * handler. If we have been triggered by a back selector or if we re-click an already selected sidebar entry
+ * that has previously transitioned the we call goBack() to transition backwards otherwise we goTo(href).
+ */
+ var end = function(e) {
+ BODY.unbind(MOVE_EV + " " + END_EV).bind(START_EV, handlePointer);
+
+ if (!IS_MOBILE && (parent.hasClass("contents") || parent.hasClass("mail"))) {
+ // Handle sidebar transitions.
+ if (_history.length == 2 && href == _history[1].href) {
+ goBack();
+ } else {
+ _history = [];
+ goTo(href);
+ }
+ } else if (parent.is("ul")) {
+ if (jthis.hasClass("radio") && !chevronClicked) { // Delegate radio button state changes.
+ Radio.handleClick(jthis, e.type);
+ } else { // Handle goTo page transition.
+ var classes = jthis.attr("class").split(" ");
+ var transition = slide; // Default animation.
+ // Look up the transition animation based upon the item's class
+ for (var i in classes) {
+ var current = classes[i];
+ var newTransition = _transitions[current];
+ if (newTransition != null) {
+ transition = newTransition;
+ break;
+ }
+ }
+ goTo(href, transition);
+ }
+ } else if (parent.hasClass("horiz-checkbox")) {
+ Checkbox.handleClick(jthis);
+ } else if (jthis.is(".back, .done, .cancel")) {
+ goBack();
+ } else if (jthis.hasClass("menu")) {
+ // For mobile devices the home button allows immediate navigation back to the main menu, which may
+ // be useful if several pages have been navigated through.
+ _history = [_history[0], {href:"#menu?", transition:null}];
+ goBack();
+ }
+ };
+
+ if (e.type == "click") {
+ e.preventDefault(); // Prevent the browser trying to navigate to the href itself onclick.
+ if (!e.originalEvent) { // If event is triggered by calling the jQuery click() method.
+ if (jthis.is("li, input:radio")) {
+ start(e);
+ end(e);
+ } else if (jthis.is("input:checkbox")) {
+ var li = jthis.closest("li.horiz-checkbox");
+
+ if (li.length == 0) { // For a normal checkbox add pageX to the event and delegate handlePointer()
+ e.pageX = 0;
+ Checkbox.handlePointer(e, e.type);
+ } else {
+ // It's a horiz-checkbox. We need to find the label associated with the checkbox.
+ var label = jthis.parent("label"); // First check if the label contains the checkbox.
+ if (label.length == 0) { // If not look for a label containing a for matching the checkbox ID.
+ label = $("label[for='" + jthis.attr("id")+"']");
+ }
+ if (label.length == 0) { // If not assume the label is the preceding sibling (a bit fragile..).
+ var items = li.children();
+ label = $(items[items.index(jthis) - 1]);
+ }
+
+ Checkbox.handleClick(label, e.type);
+ }
+ }
+ }
+ } else { // Event type is mousedown or touchstart so call main event start handler.
+ start(e);
+ }
+ };
+
+ /**
+ * This method handles keyboard input. Its main purpose is to detect the return key being pressed and if it
+ * has this method will attempt to trigger the handler bound to the right button, which should be a done/submit.
+ */
+ var handleKeyboard = function(e) {
+ if (e.which == 13) { // Handle return key;
+ // When the return key is pressed find any right button present in the header and trigger a click
+ // on it, this should have the effect of triggering the done/submit handler for the form.
+ var jthis = $(e.target);
+ var done = jthis.closest(".main, .popup").find(".header a.right.button");
+ done.trigger(START_EV).trigger(END_EV);
+ }
+ };
+
+//-------------------------------------------------------------------------------------------------------------------
+// Page Navigation Methods
+//-------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * This event handler handles the synthetic refresh event that may be triggered on a top level page containing
+ * a scroll-area. The handler uses the id of the page to index the iScroll object then calls its refresh().
+ */
+ var handleRefresh = function(e) {
+ var id = $(this).attr("id");
+ if (_scrollers[id] != null) {
+ _scrollers[id].refresh();
+ }
+ }
+
+ /**
+ * This method transitions to a selected destination. If the destination is "#" it simply returns, if there
+ * is no history the destination page is shown otherwise we transition using an animation.
+ * The ".split("?")[0]" blocks are there to cater for the case where the destination URL contains data to
+ * be passed between page fragments, where the data is delimited by a "?" and separated by "&".
+ */
+ var goTo = function(destination, transition) {
+ iTablet.location = new Location(destination);
+ var previous = (_history.length == 0) ? null : _history[0].href;
+
+ if (destination == "#" || destination == previous) { // The second test guards against multiple clicks
+ return;
+ } else if (!IS_MOBILE && _history.length == 0) {
+ var pages = $(".main");
+ $(pages).each(function(index) {
+ var jthis = $(this);
+ var id = jthis.attr("id");
+ if (("#" + id) == destination.split("?")[0]) {
+ jthis.show().trigger("show").find(".active").removeClass("active");
+ _scrollers[id].refresh(); // Refresh the touch scroller on the new page.
+ _history.unshift({href:destination, transition:null});
+ } else {
+ jthis.hide().trigger("hide");
+ }
+ });
+ } else {
+ var currentPage = $(_history[0].href.split("?")[0]);
+ var newPage = $(destination.split("?")[0]);
+ transition(currentPage, newPage, false);
+ _scrollers[newPage.attr("id")].refresh(); // Refresh the touch scroller on the new page.
+ _history.unshift({href:destination, transition:transition});
+ }
+ };
+
+ /**
+ * This method transitions back to the previous item in the history using an animation.
+ * The ".split("?")[0]" blocks are there to cater for the case where the fragment URLs contain data to
+ * be passed between page fragments, where the data is delimited by a "?" and separated by "&".
+ */
+ var goBack = function() {
+ if (_history.length > 1) {
+ iTablet.location = new Location(_history[1].href);
+ var transition = _history[0].transition;
+ var currentPage = $(_history[0].href.split("?")[0]);
+ var newPage = $(_history[1].href.split("?")[0]);
+ transition(currentPage, newPage, true);
+ _scrollers[newPage.attr("id")].refresh(); // Refresh the touch scroller on the new page.
+ _history.shift();
+
+ // Hide virtual keyboard.
+ document.activeElement.blur();
+ }
+ };
+
+//-------------------------------------------------------------------------------------------------------------------
+// Animations
+//-------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * This method detects support for CSS3 animations and transitions and uses them if present. It will attempt
+ * to use translate3d if present as this is most likely to be GPU accelerated and uses translate as fallback.
+ * In an ideal world this would be set up in a stylesheet using media queries, but unfortunately using
+ * prefixes for all of the keyframes is rather verbose and untidy and media query of translate3d only seems
+ * to be supported in WebKit, so scripting is needed whatever. This method "injects" the relevant styles.
+ */
+ var initialiseCSSAnimations = function() {
+ // TODO It'd be nicer to use feature detection but that can be hard to get right - how do we *reliably"
+ // detect support for animationend and transitionend events, which are essential for these animations???
+ if ((/android/gi).test(navigator.appVersion) || OPERA_VERSION <= 12.01) {
+ // Android has poor CSS3 animation support so use jQuery.
+ // Opera <= 12.01 doesn't have animationend which messes up state management, what's worse is that it
+ // passes the animationSupported test, so just bomb out early Opera 12.01 at least fails that...
+ return;
+ }
+
+ var domPrefixes = ["Webkit", "Moz", "O", "ms", "Khtml"];
+
+ // For the following lookups ensure that prefix key is forced to lower case!!
+ var transitionEndLookup = { // Lookup transitionend Event. Note prefixes are different to DOM prefixes
+ "" : "transitionend",
+ "webkit" : "webkitTransitionEnd",
+ "moz" : "transitionend",
+ "o" : "oTransitionEnd",
+ "ms" : "transitionend"
+ };
+
+ var animationEndLookup = { // Lookup transitionend Event. Note prefixes are different to DOM prefixes
+ "" : "animationend",
+ "webkit" : "webkitAnimationEnd",
+ "moz" : "animationend",
+ "o" : "oAnimationEnd",
+ "ms" : "transitionend"
+ };
+
+ var has3d = false;
+ var domPrefix = "";
+ var prefix = "";
+
+ var style = $("<style/>");
+ var styles = style[0].style;
+
+ // We first check for animation-name and transform CSS support.
+ var animationSupported = styles.animationName && styles.transform ? true : false;
+ var animationend = "animationend";
+ var transitionend = "transitionend";
+
+ if (!animationSupported) { // If prefix free versions not present check for prefixed versions.
+ var length = domPrefixes.length;
+ for (var i = 0; i < length; i++) {
+ if (styles[domPrefixes[i] + "AnimationName"] !== undefined) {
+ animationend = animationEndLookup[domPrefixes[i].toLowerCase()];
+ transitionend = transitionEndLookup[domPrefixes[i].toLowerCase()];
+
+ var domPrefix = domPrefixes[i];
+ prefix = "-" + domPrefix.toLowerCase() + "-";
+
+ if (styles[domPrefix + "Transform"] !== undefined) {
+ if (styles[domPrefix + "Perspective"] !== undefined) {
+ has3d = true;
+ }
+ animationSupported = true;
+ break;
+ } else {
+ return;
+ }
+ }
+ }
+ }
+
+ ANIMATION_END_EV = animationend;
+ TRANSITION_END_EV = transitionend;
+
+ if (animationSupported) { // Animating transforms is supported if this is true.
+ // Webkit's 3D transforms are passed off to the browser's own graphics renderer so may give a
+ // false positive, the test below should double check that 3d is indeed supported.
+ if (has3d && prefix == "-webkit-") {
+ has3d = 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix();
+ }
+
+ var s = ".sidebar, .main, .popup, .popup-window, .popup-container, ul li {" +
+ prefix + "animation: 350ms ease-in-out;}";
+ // Define the key animation styles. cssSlide simply adds these classes to trigger the animation.
+ s += ".slideIn {" + prefix + "animation-name: slideinfromright;}";
+ s += ".slideOut {" + prefix + "animation-name: slideouttoleft;}";
+ s += ".slideIn.reverse {" + prefix + "animation-name: slideinfromleft;}";
+ s += ".slideOut.reverse {" + prefix + "animation-name: slideouttoright;}";
+ s += ".fade {" + prefix + "animation-name: fadehighlight;}";
+ s += ".slideUp {" + prefix + "animation-name: slideinfrombottom;}";
+ s += ".slideDown {" + prefix + "animation-name: slideouttobottom;}";
+ s += ".dissolveIn50 {" + prefix + "animation-name: dissolvein50;}";
+ s += ".dissolveOut50 {" + prefix + "animation-name: dissolveout50;}";
+
+ // Helper method to render transform using translate3d if supported or translate if not.
+ var renderTranslate = function(val) {
+ return prefix + "transform: translate" + (has3d ? "3d(" : "(") + val + (has3d ? ", 0);" : ");");
+ };
+
+ // Implement setting the left css attribute of the supplied element using css translate.
+ var cssSetPosition = function(element, offset, left, duration) {
+ // Invoked when the animation completes, resets styles.
+ var completeCallback = function() {
+ element.removeAttr("style").css("left", left + "px").unbind(TRANSITION_END_EV);
+ };
+
+ // If a duration is provided then use a transition to animate the transform.
+ if (duration != null) {
+ element.css(prefix + "transition", prefix + "transform " + duration + "ms ease-out 0ms").
+ bind(TRANSITION_END_EV, completeCallback);
+ }
+
+ element.css(prefix + "transform",
+ "translate" + (has3d ? "3d(" : "(") + (left + offset) + "px, 0" + (has3d ? ", 0)" : ")"));
+ };
+
+ var keyframes = prefix + "keyframes ";
+
+ // Now define the keframes for the animations.
+ s += "@" + keyframes + "slideinfromright {";
+ s += "from {" + renderTranslate("100%, 0") + "}";
+ s += "to {" + renderTranslate("0, 0") + "}}";
+
+ s += "@" + keyframes + "slideouttoleft {";
+ s += "from {" + renderTranslate("0, 0") + "}";
+ s += "to {" + renderTranslate("-100%, 0") + "}}";
+
+ s += "@" + keyframes + "slideinfromleft {";
+ s += "from {" + renderTranslate("-100%, 0") + "}";
+ s += "to {" + renderTranslate("0, 0") + "}}";
+
+ s += "@" + keyframes + "slideouttoright {";
+ s += "from {" + renderTranslate("0, 0") + "}";
+ s += "to {" + renderTranslate("100%, 0") + "}}";
+
+ s += "@" + keyframes + "fadehighlight {";
+ s += "from {background-color: #035de7; color: #ffffff;}";
+ s += "to {background-color: #f7f7f7; color: #324F85;}}";
+
+ s += "@" + keyframes + "slideinfrombottom {";
+ s += "from {" + renderTranslate("0, 100%") + "}";
+ s += "to {" + renderTranslate("0, 0") + "}}";
+
+ s += "@" + keyframes + "slideouttobottom {";
+ s += "from {" + renderTranslate("0, 0") + "}";
+ s += "to {" + renderTranslate("0, 120%") + "}}";
+
+ s += "@" + keyframes + "dissolvein50 {";
+ s += "from {background-color: rgba(0, 0, 0, 0.0);}";
+ s += "to {background-color: rgba(0, 0, 0, 0.49);}}"; // Setting to 0.49 not 0.5 prevents Firefox glitch.
+
+ s += "@" + keyframes + "dissolveout50 {";
+ s += "from {background-color: rgba(0, 0, 0, 0.5);}";
+ s += "to {background-color: rgba(0, 0, 0, 0.0);}}";
+
+ style.append(s);
+ $("head").append(style); // "inject" animation styles into DOM.
+ slide = cssSlide; // Override slide method with the cssSlide version.
+ fade = cssFade; // Override fade method with the cssFade version.
+ popup = cssPopup; // Override fade method with the cssFade version.
+ setPosition = cssSetPosition;
+ }
+ };
+
+ /**
+ * Implement a simple colour fade animation using a look up table to fade active colour back to background.
+ * This is the default fade implementation, which may be overridden if CSS3 animations are supported.
+ */
+ var fade = function(selected) {
+ var table = [{"background-color": "#0360e8", "color": "#ffffff"},
+ {"background-color": "#337feb", "color": "#ffffff"},
+ {"background-color": "#669eef", "color": "#ffffff"},
+ {"background-color": "#99b8f0", "color": "#324F85"},
+ {"background-color": "#c0d7f3", "color": "#324F85"},
+ {"background-color": "#f6f6f6", "color": "#324F85"}];
+
+ var stepCallback = function(i) {
+ if (i < 6) {
+ selected.css(table[i]); // Set style from look up table.
+ setTimeout(function() {stepCallback(i + 1);}, 50); // 7 steps at 50ms per step = 350ms
+ } else {
+ selected.removeAttr("style"); // When the animation ends remove the styles we've just added.
+ }
+ };
+
+ if (selected.is(":visible")) { // Only apply animation is element is visible.
+ selected.removeClass("active");
+ stepCallback(0);
+ } else {
+ selected.removeClass("active");
+ }
+ };
+
+ /**
+ * Implement a colour fade using a CSS3 animation to fade active colour back to background.
+ */
+ var cssFade = function(selected) {
+ // Invoked when the animation completes, resets styles.
+ var completeCallback = function() {
+ selected.removeClass("fade").unbind(ANIMATION_END_EV);
+ };
+
+ if (selected.is(":visible")) { // Only apply animation is element is visible.
+ selected.removeClass("active").addClass("fade").bind(ANIMATION_END_EV, completeCallback);
+ } else {
+ selected.removeClass("active");
+ }
+ };
+
+ /**
+ * Implement a horizontal slide from the currentPage to the newPage using jQuery animate() of the left and right
+ * css properies. If isReverse is true the slide is left to right otherwise the slide is right to left.
+ * This is the default slide implementation, which may be overridden if CSS3 animations are supported.
+ */
+ var slide = function(currentPage, newPage, isReverse) {
+ var width = isReverse ? -currentPage.outerWidth() : currentPage.outerWidth();
+ var left = newPage.hasClass("popup") ? 0 : _mainLeft;
+
+ // Invoked when the animation completes, resets style and hides the old page and rebinds the START_EV.
+ var completeCallback = function() {
+ currentPage.hide().trigger("hide"); // Hide the current page after animation completes.
+ currentPage.css({"left": left + "px", "right": "0"}); // Reset css back to original settings.
+ BODY.bind(START_EV, handlePointer); // Re-enable START_EV when transition completes.
+ };
+
+ BODY.unbind(START_EV, handlePointer); // Disable START_EV until transition completes.
+ newPage.css({"left": left + width + "px", "right": -width + "px"}).show().trigger("show").
+ animate({left: left, right: 0}, 350);
+ var selected = newPage.find(".active").removeClass("active");
+ if (isReverse) {
+ fade(selected);
+ }
+ currentPage.animate({left: left - width, right: width}, 350, completeCallback);
+ };
+
+ /**
+ * Implement a horizontal slide from the currentPage to the newPage using a CSS3 animation.
+ * This should give a much smoother animation than the jQuery one and is GPU accelerated on some devices.
+ * If isReverse is true the slide is left to right otherwise the slide is right to left.
+ */
+ var cssSlide = function(currentPage, newPage, isReverse) {
+ var width = isReverse ? -currentPage.outerWidth() : currentPage.outerWidth();
+ var classes = "slideIn slideOut reverse";
+
+ // Invoked when the animation completes, resets styles and hides the old page and rebinds the START_EV.
+ var completeCallback = function() {
+ newPage.removeClass(classes);
+ currentPage.hide().removeClass(classes).unbind(ANIMATION_END_EV, completeCallback);
+ BODY.bind(START_EV, handlePointer); // Re-enable START_EV when transition completes.
+ };
+
+ BODY.unbind(START_EV, handlePointer); // Disable START_EV until transition completes.
+
+ var reverse = isReverse ? " reverse" : "";
+ newPage.show().trigger("show").addClass("slideIn" + reverse);
+ var selected = newPage.find(".active").removeClass("active");
+ if (isReverse) {
+ fade(selected);
+ }
+ currentPage.bind(ANIMATION_END_EV, completeCallback).addClass("slideOut" + reverse);
+ };
+
+ /**
+ * Implement a pop up to the newPage using jQuery animate() of the top, bottom and rgba css properies.
+ * If isReverse is true the popup slides down otherwise it slides up.
+ * This is the default popup implementation, which may be overridden if CSS3 animations are supported.
+ */
+ var popup = function(currentPage, newPage, isReverse) {
+ fade(currentPage.find(".active"));
+ var height = currentPage.outerWidth();
+ var background = $(".popup-window");
+ var container = $(".popup-container");
+
+ var setOpacity = function(i) { // Animate opacity value.
+ if (!IS_IE || IE_VERSION > 8) { // CSS rgba is supported by modern browsers.
+ background.css({"background-color": "rgba(0, 0, 0, 0." + i + ")"});
+ } else { // IE8 and below don't support rgba so use MS DXImageTransform filter.
+ // This is a bit subtle, unfortunately progid:DXImageTransform messes with the fonts so we only use
+ // it to animate the opacity, for the final black with 50% alpha effect we add the "smoked" style
+ // which uses a png image background, the combination gives fairly smooth animation and normal font.
+ var hexAlpha = (Math.round(25.6 * i)).toString(16); // Convert index to a hex alpha value.
+ hexAlpha = (hexAlpha.length < 2) ? "0" + hexAlpha : hexAlpha; // Pad to two hex digits if necessary.
+ hexAlpha = "#" + hexAlpha + "000000"; // Modify the alpha of a black background.
+ background.css({"filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr=" +
+ hexAlpha + ",endColorstr=" + hexAlpha + ")"});
+ }
+ };
+
+ var removeStyles = function(i) {
+ if (IE_VERSION <= 6) { // For IE6 we've added other dynamic styles, so we need to preserve those.
+ } else { // For every other browser we remove all dynamic styling.
+ background.removeAttr("style");
+ }
+ };
+
+ var fadeInBackground = function(i) { // Animate rgba opacity property from 0.0 to 0.5.
+ if (i < 6) {
+ setOpacity(i);
+ setTimeout(function() {fadeInBackground(i + 1);}, 50);
+ } else {
+ removeStyles(); // When the animation ends remove the styles we've just added.
+ background.addClass("smoked"); // Only does anything for IE < 9
+ }
+ };
+
+ var fadeOutBackground = function(i) { // Animate rgba opacity property from 0.5 to 0.0.
+ if (i >= 0) {
+ setOpacity(i);
+ setTimeout(function() {fadeOutBackground(i - 1);}, 50);
+ } else {
+ removeStyles(); // When the animation ends remove the styles we've just added.
+ background.hide();
+ newPage.trigger("show");
+ }
+ };
+
+ if (isReverse) {
+ // Wrapping in a timeout prevents IE8 glitching button styles when returning from :active state.
+ setTimeout(function() {
+ background.removeClass("smoked");
+ fadeOutBackground(5);
+ }, 10);
+
+ container.css({"top": "64px", "bottom": "64px"}).
+ animate({top: height + "px", bottom: 128 - height + "px"}, 350);
+ } else {
+ $(".popup").hide();
+ newPage.show().trigger("show");
+ background.show();
+ fadeInBackground(0);
+ container.css({"top": height + "px", "bottom": 128 - height + "px"}).
+ animate({top: "64px", bottom: "64px"}, 350);
+ }
+ };
+
+ /**
+ * Implement a pop up to the newPage using a CSS3 animation.
+ * This should give a much smoother animation than the jQuery one and is GPU accelerated on some devices.
+ * If isReverse is true the popup slides down otherwise it slides up.
+ */
+ var cssPopup = function(currentPage, newPage, isReverse) {
+ fade(currentPage.find(".active"));
+ var background = $(".popup-window");
+ var container = $(".popup-container");
+ background.removeClass("dissolveIn50 dissolveOut50");
+ container.removeClass("slideUp slideDown");
+
+ // Invoked when the animation completes, hides the background.
+ var completeCallback = function() {
+ background.hide();
+ container.unbind(ANIMATION_END_EV, completeCallback);
+ newPage.trigger("show");
+ };
+
+ if (isReverse) {
+ background.addClass("dissolveOut50");
+ container.bind(ANIMATION_END_EV, completeCallback).addClass("slideDown");
+ } else {
+ $(".popup").hide();
+ newPage.show().trigger("show");
+ background.show().addClass("dissolveIn50");
+ container.addClass("slideUp");
+ }
+ };
+
+ /**
+ * Implement setting the left css attribute of the supplied element using standard jQuery css call.
+ */
+ var setPosition = function(element, offset, left, duration) {
+ if (duration != null) {
+ element.animate({left: left}, duration);
+ } else {
+ element.css("left", left + "px");
+ }
+ };
+
+//-------------------------------------------------------------------------------------------------------------------
+// Add HTML5 placeholder support to browsers that don't have native support.
+//-------------------------------------------------------------------------------------------------------------------
+
+ var addPlaceholderSupport = function(inputs) {
+ inputs.each(function() {
+ var jthis = $(this);
+ // Add textarea class to allow textarea placeholder to be styled differently to input placeholder.
+ var classes = jthis.is("textarea") ? "placeholder textarea" : "placeholder";
+
+ jthis.focus(function() {
+ jthis.siblings("span").hide();
+ }).blur(function() {
+ if (jthis.val() == "") {
+ jthis.siblings("span").show();
+ }
+ }).parent().append("<span class='" + classes + "'>" + jthis.attr("placeholder") + "</span>");
+ });
+ };
+
+//-------------------------------------------------------------------------------------------------------------------
+// Some IE specific code to manipulate additional styles to help "pretty up" earlier versions of IE.
+//-------------------------------------------------------------------------------------------------------------------
+
+ /**
+ * For IE6 adjust the size as it doesn't seem to be computed correctly in pure CSS.
+ * To be really nice we should probably compute SCROLLBAR, HEADER, PADDING but hey, it's only for IE6 :-)
+ */
+ var adjustSize = function() {
+ var SCROLLBAR = 20;
+ var HEADER = 44;
+ var PADDING = 128;
+ var width = BODY.outerWidth() + SCROLLBAR;
+ var height = $(window).outerHeight();
+ var mainWidth = width - _mainLeft;
+ $(".main").css({"width": mainWidth + "px"});
+ $(".main, .sidebar").css({"height": (height - HEADER) + "px"});
+ $(".popup-window").css({"width": width + "px", "height": height + "px"});
+ $(".popup-container").css({"width": (width - width * 0.4) + "px",
+ "height": (height - (PADDING + HEADER)) + "px"});
+ // Render each list (this reskins checkboxes & radio buttons and adds the border radius on old browsers).
+ $("ul.list").each(function() {iTablet.renderList($(this));});
+ };
+
+ /**
+ * Among its long list of failings IE6 doesn't properly support multiple classes. The active class is used in
+ * several places, so this method overrides jQuery's addClass and removeClass in order to create IE6 specific
+ * classes when the active or checked class is added or removed. It's a messy, but fairly effective approach.
+ */
+ var mergeClasses = function() {
+ // Merge blue and back classes - this only works if blue is added statically which is how it's expected to be.
+ $("a.blue.back.button").addClass("blue-back");
+
+ var addClass = jQuery.fn.addClass; // Retrieve original jQuery addClass.
+ jQuery.fn.addClass = function() { // Override jQuery addClass.
+ var jthis = $(this);
+ // Execute the original method and save result.
+ var result = addClass.apply(this, arguments);
+
+ var length = arguments.length;
+ for (var i = 0; i < length; i++) {
+ if (arguments[i] == "checked") {
+ if (jthis.hasClass("arrow")) {
+ jthis.addClass("ie6-checked-arrow");
+ }
+ }
+
+ if (arguments[i] == "active") {
+ if (jthis.hasClass("arrow")) {
+ jthis.addClass("ie6-arrow-active");
+ }
+
+ if (jthis.hasClass("checked")) {
+ jthis.addClass("ie6-checked-active");
+ }
+
+ if (jthis.hasClass("radio") && jthis.hasClass("arrow")) {
+ jthis.addClass("ie6-radio-arrow-active");
+ }
+
+ if (jthis.hasClass("checked") && jthis.hasClass("arrow")) {
+ jthis.addClass("ie6-checked-arrow-active");
+ }
+ }
+ }
+
+ return result;
+ };
+
+ var removeClass = jQuery.fn.removeClass; // Retrieve original jQuery removeClass.
+ jQuery.fn.removeClass = function() { // Override jQuery removeClass.
+ var jthis = $(this);
+ // Execute the original method and save result.
+ var result = removeClass.apply(this, arguments);
+
+ var length = arguments.length;
+ for (var i = 0; i < length; i++) {
+ if (arguments[i] == "checked") {
+ jthis.removeClass("ie6-checked-arrow");
+ }
+
+ if (arguments[i] == "active") {
+ jthis.removeClass("ie6-arrow-active ie6-checked-active ie6-radio-arrow-active ie6-checked-arrow-active");
+ }
+ }
+
+ return result;
+ };
+ };
+
+ /**
+ * Sort out quirks for various versions of IE less than 9 - IE9 is fortunately *fairly* well behaved.
+ */
+ var fixIEQuirks = function() {
+ if (IE_VERSION < 8) { // For IE7 and below.
+ $("textarea").parent().addClass("textarea"); // Add textarea class to parent <li> - used by IE7 CSS styles.
+
+ // Wrapping the sidebar in another div with zoom: 1 to enable "layout mode" fixes an
+ // annoying page transition slide animation quirk with IE < 8.
+ BODY.prepend($("<div id='sidebar-wrapper'></div>"));
+ $("#sidebar-wrapper").append($("#menu"));
+
+ // Sort out button styling and issue with :active not being switched off.
+ $("a.button").attr('hideFocus', 'hidefocus').
+ append("<div class='before'></div><div class='after'></div>").
+ bind("click mouseleave", function() {this.blur();});
+ $("ul.contents li a").attr('hideFocus', 'hidefocus'); // Fix lack of outline: none; in IE < 8
+ }
+
+ if (IE_VERSION < 7) { // IE6 is a real drag......
+ adjustSize(); // Set css width and height as it doesn't seem to be computed correctly in pure CSS.
+ mergeClasses(); // IE < 7 doesn't support multiple classes so merge them into IE specific class.
+ $(window).resize(adjustSize);
+ } else { // For IE7 and above just render list.
+ // Render each list (this reskins checkboxes & radio buttons and adds the border radius on old browsers).
+ $("ul.list").each(function() {iTablet.renderList($(this));});
+ }
+ }
+
+//-------------------------------------------------------------------------------------------------------------------
+// Initialise when DOM loads using (shorthand) jQuery.ready()
+//-------------------------------------------------------------------------------------------------------------------
+
+ $(function() {
+ /*
+ * These handlers help make the UI behave more like a User Interface than a web page. The selectstart handler
+ * disables selection on everything other than input/textarea etc. the dragstart handler disables IE image
+ * dragging, the touchmove handler disables mobile Safari web page "bounce" and the contextmenu handler
+ * disables the right click context menu. In a web page disabling this stuff might be frowned on, but in
+ * a web app it makes the application look and feel much more like a native app, which is rather the point.
+ */
+ $(document).bind("selectstart contextmenu", function(e) {
+ return $(e.target).is('input, textarea, select, option');});
+ $(document).bind("dragstart touchmove submit", function (e) {e.preventDefault();});
+ $(document).bind("orientationchange", function (e) {scrollTo(0, 0);}); // Make sure position is OK
+ $(document).keyup(handleKeyboard);
+
+ // jQuery object for body is used in several places so let's cache it.
+ BODY = $("body");
+
+ _mainLeft = parseInt($(".main").css("left"), 10);
+
+ //IS_MOBILE = BODY.hasClass("mobile"); // We use the class "mobile" for mobile devices.
+ IS_MOBILE = (_mainLeft == 0); // For mobile devices there is no sidebar.
+ if (IS_MOBILE) {
+ _history = [{href:"#menu?", transition:null}];
+ }
+
+ // Prevent the browser trying to navigate to the href itself onclick then bind pointer Events to handlePointer.
+ BODY.bind(START_EV + " click", handlePointer);
+
+ // Ensure various form fields behave correctly with iScroll.
+ $("input, textarea, select").bind(START_EV, function(e) {e.stopPropagation();});
+
+ // Detect input and textarea placeholders separately as some browsers (Opera 11) have native support for
+ // input placeholders but not textarea placeholders.
+ if (!("placeholder" in $("<input>")[0])) { // Add HTML5 input placeholder support if not natively present.
+ addPlaceholderSupport($("input[placeholder]"));
+ }
+
+ if (!("placeholder" in $("<textarea>")[0])) { // Add HTML5 textarea placeholder support if not natively present.
+ addPlaceholderSupport($("textarea[placeholder]"));
+ }
+
+ $.event.special.textchange = new TextChange(); // Add support for textchange Events on text input and textarea.
+
+ // This block looks for scroll-areas and constructs an iScroll touch scroller. Note that scrollers are indexed
+ // by the containing "main" page not by the id of the scroll-area. The latter id is only used by iScroll itself.
+ $(".scroll-area").each(function(index) {
+ var parent = $(this).parent();
+ parent.bind("refresh", handleRefresh); // Bind the synthetic refresh event to the refresh handler
+ var parentId = parent.attr("id");
+
+ if (TOUCH_ENABLED) {
+ _scrollers[parentId] = new iScroll(this);
+ } else { // Adds a dummy scroller object if not a touch device.
+ _scrollers[parentId] = {refresh: function() {}};
+ }
+ });
+
+ initialiseCSSAnimations();
+ _transitions = {"pop": popup};
+
+ iTablet.location = new Location("#" + $(".main").attr("id"));
+
+ if (IS_IE) {
+ fixIEQuirks();
+ } else {
+ // Render each list (this reskins checkboxes & radio buttons and adds the border radius on old browsers).
+ $("ul.list").each(function() {iTablet.renderList($(this));});
+ }
+
+ /*
+ * iOS6 safari has a number of "quirks" that seem to be related to overly aggressive caching, one of these
+ * these relates to attempting to reuse browser connections before the HTTP response has returned. In theory
+ * this may be a good thing as it allows better "pipelining" on persistent connections, but in practice
+ * if the "long polling" pattern is being used it can really mess things up for image "rollovers" when
+ * dynamic state gets changed. This usually manifests itself by the active images taking an age to appear.
+ * The following line works around this issue by initially adding the active state to the relevant items
+ * this forces the active images to be loaded, which are then subsequently cached.
+ */
+ $("div.main ul.list li").addClass("active");
+
+ $(".main, .popup-window").hide();
+ });
+};
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/jquery.js b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/jquery.js
new file mode 100644
index 0000000000..198b3ff07d
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/itablet/scripts/jquery.js
@@ -0,0 +1,4 @@
+/*! jQuery v1.7.1 jquery.com | jquery.org/license */
+(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cl||(cl=c.createElement("iframe"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode==="CSS1Compat"?"<!doctype html>":"")+"<html><body>"),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g<i;g++){if(g===1)for(h in a.converters)typeof h=="string"&&(e[h.toLowerCase()]=a.converters[h]);l=k,k=d[g];if(k==="*")k=l;else if(l!=="*"&&l!==k){m=l+" "+k,n=e[m]||e["* "+k];if(!n){p=b;for(o in e){j=o.split(" ");if(j[0]===l||j[0]==="*"){p=e[j[1]+" "+k];if(p){o=e[o],o===!0?n=p:p===!0&&(n=o);break}}}}!n&&!p&&f.error("No conversion from "+m.replace(" "," to ")),n!==!0&&(c=n?n(c):p(o(c)))}}return c}function cb(a,c,d){var e=a.contents,f=a.dataTypes,g=a.responseFields,h,i,j,k;for(i in g)i in d&&(c[g[i]]=d[i]);while(f[0]==="*")f.shift(),h===b&&(h=a.mimeType||c.getResponseHeader("content-type"));if(h)for(i in e)if(e[i]&&e[i].test(h)){f.unshift(i);break}if(f[0]in d)j=f[0];else{for(i in d){if(!f[0]||a.converters[i+" "+f[0]]){j=i;break}k||(k=i)}j=j||k}if(j){j!==f[0]&&f.unshift(j);return d[j]}}function ca(a,b,c,d){if(f.isArray(b))f.each(b,function(b,e){c||bE.test(a)?d(a,e):ca(a+"["+(typeof e=="object"||f.isArray(e)?b:"")+"]",e,c,d)});else if(!c&&b!=null&&typeof b=="object")for(var e in b)ca(a+"["+e+"]",b[e],c,d);else d(a,b)}function b_(a,c){var d,e,g=f.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((g[d]?a:e||(e={}))[d]=c[d]);e&&f.extend(!0,a,e)}function b$(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h=a[f],i=0,j=h?h.length:0,k=a===bT,l;for(;i<j&&(k||!l);i++)l=h[i](c,d,e),typeof l=="string"&&(!k||g[l]?l=b:(c.dataTypes.unshift(l),l=b$(a,c,d,e,l,g)));(k||!l)&&!g["*"]&&(l=b$(a,c,d,e,"*",g));return l}function bZ(a){return function(b,c){typeof b!="string"&&(c=b,b="*");if(f.isFunction(c)){var d=b.toLowerCase().split(bP),e=0,g=d.length,h,i,j;for(;e<g;e++)h=d[e],j=/^\+/.test(h),j&&(h=h.substr(1)||"*"),i=a[h]=a[h]||[],i[j?"unshift":"push"](c)}}}function bC(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?bx:by,g=0,h=e.length;if(d>0){if(c!=="border")for(;g<h;g++)c||(d-=parseFloat(f.css(a,"padding"+e[g]))||0),c==="margin"?d+=parseFloat(f.css(a,c+e[g]))||0:d-=parseFloat(f.css(a,"border"+e[g]+"Width"))||0;return d+"px"}d=bz(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0;if(c)for(;g<h;g++)d+=parseFloat(f.css(a,"padding"+e[g]))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+e[g]+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+e[g]))||0);return d+"px"}function bp(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bf,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bo(a){var b=c.createElement("div");bh.appendChild(b),b.innerHTML=a.outerHTML;return b.firstChild}function bn(a){var b=(a.nodeName||"").toLowerCase();b==="input"?bm(a):b!=="script"&&typeof a.getElementsByTagName!="undefined"&&f.grep(a.getElementsByTagName("input"),bm)}function bm(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bl(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bk(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bj(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c,d,e,g=f._data(a),h=f._data(b,g),i=g.events;if(i){delete h.handle,h.events={};for(c in i)for(d=0,e=i[c].length;d<e;d++)f.event.add(b,c+(i[c][d].namespace?".":"")+i[c][d].namespace,i[c][d],i[c][d].data)}h.data&&(h.data=f.extend({},h.data))}}function bi(a,b){return f.nodeName(a,"table")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function U(a){var b=V.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function T(a,b,c){b=b||0;if(f.isFunction(b))return f.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return f.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=f.grep(a,function(a){return a.nodeType===1});if(O.test(b))return f.filter(b,d,!c);b=f.filter(b,d)}return f.grep(a,function(a,d){return f.inArray(a,b)>=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c<d;c++)b[a[c]]=!0;return b}var c=a.document,d=a.navigator,e=a.location,f=function(){function J(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(J,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j<k;j++)if((a=arguments[j])!=null)for(c in a){d=i[c],f=a[c];if(i===f)continue;l&&f&&(e.isPlainObject(f)||(g=e.isArray(f)))?(g?(g=!1,h=d&&e.isArray(d)?d:[]):h=d&&e.isPlainObject(d)?d:{},i[c]=e.extend(l,h,f)):f!==b&&(i[c]=f)}return i},e.extend({noConflict:function(b){a.$===e&&(a.$=g),b&&a.jQuery===e&&(a.jQuery=f);return e},isReady:!1,readyWait:1,holdReady:function(a){a?e.readyWait++:e.ready(!0)},ready:function(a){if(a===!0&&!--e.readyWait||a!==!0&&!e.isReady){if(!c.body)return setTimeout(e.ready,1);e.isReady=!0;if(a!==!0&&--e.readyWait>0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g<h;)if(c.apply(a[g++],d)===!1)break}else if(i){for(f in a)if(c.call(a[f],f,a[f])===!1)break}else for(;g<h;)if(c.call(a[g],g,a[g++])===!1)break;return a},trim:G?function(a){return a==null?"":G.call(a)}:function(a){return a==null?"":(a+"").replace(k,"").replace(l,"")},makeArray:function(a,b){var c=b||[];if(a!=null){var d=e.type(a);a.length==null||d==="string"||d==="function"||d==="regexp"||e.isWindow(a)?E.call(c,a):e.merge(c,a)}return c},inArray:function(a,b,c){var d;if(b){if(H)return H.call(b,a,c);d=b.length,c=c?c<0?Math.max(0,d+c):c:0;for(;c<d;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,c){var d=a.length,e=0;if(typeof c.length=="number")for(var f=c.length;e<f;e++)a[d++]=c[e];else while(c[e]!==b)a[d++]=c[e++];a.length=d;return a},grep:function(a,b,c){var d=[],e;c=!!c;for(var f=0,g=a.length;f<g;f++)e=!!b(a[f],f),c!==e&&d.push(a[f]);return d},map:function(a,c,d){var f,g,h=[],i=0,j=a.length,k=a instanceof e||j!==b&&typeof j=="number"&&(j>0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i<j;i++)f=c(a[i],i,d),f!=null&&(h[h.length]=f);else for(g in a)f=c(a[g],g,d),f!=null&&(h[h.length]=f);return h.concat.apply([],h)},guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=F.call(arguments,2),g=function(){return a.apply(c,f.concat(F.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g},access:function(a,c,d,f,g,h){var i=a.length;if(typeof c=="object"){for(var j in c)e.access(a,j,c[j],f,g,d);return a}if(d!==b){f=!h&&f&&e.isFunction(d);for(var k=0;k<i;k++)g(a[k],c,f?d.call(a[k],k,g(a[k],c)):d,h);return a}return i?g(a[0],c):b},now:function(){return(new Date).getTime()},uaMatch:function(a){a=a.toLowerCase();var b=r.exec(a)||s.exec(a)||t.exec(a)||a.indexOf("compatible")<0&&u.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}e.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function(d,f){f&&f instanceof e&&!(f instanceof a)&&(f=a(f));return e.fn.init.call(this,d,f,b)},a.fn.init.prototype=a.fn;var b=a(c);return a},browser:{}}),e.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){I["[object "+b+"]"]=b.toLowerCase()}),z=e.uaMatch(y),z.browser&&(e.browser[z.browser]=!0,e.browser.version=z.version),e.browser.webkit&&(e.browser.safari=!0),j.test(" ")&&(k=/^[\s\xA0]+/,l=/[\s\xA0]+$/),h=e(c),c.addEventListener?B=function(){c.removeEventListener("DOMContentLoaded",B,!1),e.ready()}:c.attachEvent&&(B=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",B),e.ready())});return e}(),g={};f.Callbacks=function(a){a=a?g[a]||h(a):{};var c=[],d=[],e,i,j,k,l,m=function(b){var d,e,g,h,i;for(d=0,e=b.length;d<e;d++)g=b[d],h=f.type(g),h==="array"?m(g):h==="function"&&(!a.unique||!o.has(g))&&c.push(g)},n=function(b,f){f=f||[],e=!a.memory||[b,f],i=!0,l=j||0,j=0,k=c.length;for(;c&&l<k;l++)if(c[l].apply(b,f)===!1&&a.stopOnFalse){e=!0;break}i=!1,c&&(a.once?e===!0?o.disable():c=[]:d&&d.length&&(e=d.shift(),o.fireWith(e[0],e[1])))},o={add:function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},remove:function(){if(c){var b=arguments,d=0,e=b.length;for(;d<e;d++)for(var f=0;f<c.length;f++)if(b[d]===c[f]){i&&f<=k&&(k--,f<=l&&l--),c.splice(f--,1);if(a.unique)break}}return this},has:function(a){if(c){var b=0,d=c.length;for(;b<d;b++)if(a===c[b])return!0}return!1},empty:function(){c=[];return this},disable:function(){c=d=e=b;return this},disabled:function(){return!c},lock:function(){d=b,(!e||e===!0)&&o.disable();return this},locked:function(){return!d},fireWith:function(b,c){d&&(i?a.once||d.push([b,c]):(!a.once||!e)&&n(b,c));return this},fire:function(){o.fireWith(this,arguments);return this},fired:function(){return!!e}};return o};var i=[].slice;f.extend({Deferred:function(a){var b=f.Callbacks("once memory"),c=f.Callbacks("once memory"),d=f.Callbacks("memory"),e="pending",g={resolve:b,reject:c,notify:d},h={done:b.add,fail:c.add,progress:d.add,state:function(){return e},isResolved:b.fired,isRejected:c.fired,then:function(a,b,c){i.done(a).fail(b).progress(c);return this},always:function(){i.done.apply(i,arguments).fail.apply(i,arguments);return this},pipe:function(a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()},promise:function(a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a}},i=h.promise({}),j;for(j in g)i[j]=g[j].fire,i[j+"With"]=g[j].fireWith;i.done(function(){e="resolved"},c.disable,d.lock).fail(function(){e="rejected"},b.disable,d.lock),a&&a.call(i,i);return i},when:function(a){function m(a){return function(b){e[a]=arguments.length>1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c<d;c++)b[c]&&b[c].promise&&f.isFunction(b[c].promise)?b[c].promise().then(l(c),j.reject,m(c)):--g;g||j.resolveWith(j,b)}else j!==a&&j.resolveWith(j,d?[a]:[]);return k}}),f.support=function(){var b,d,e,g,h,i,j,k,l,m,n,o,p,q=c.createElement("div"),r=c.documentElement;q.setAttribute("className","t"),q.innerHTML=" <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>",d=q.getElementsByTagName("*"),e=q.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=q.getElementsByTagName("input")[0],b={leadingWhitespace:q.firstChild.nodeType===3,tbody:!q.getElementsByTagName("tbody").length,htmlSerialize:!!q.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:q.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete q.test}catch(s){b.deleteExpando=!1}!q.addEventListener&&q.attachEvent&&q.fireEvent&&(q.attachEvent("onclick",function(){b.noCloneEvent=!1}),q.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),q.appendChild(i),k=c.createDocumentFragment(),k.appendChild(q.lastChild),b.checkClone=k.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,k.removeChild(i),k.appendChild(q),q.innerHTML="",a.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",q.style.width="2px",q.appendChild(j),b.reliableMarginRight=(parseInt((a.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(q.attachEvent)for(o in{submit:1,change:1,focusin:1})n="on"+o,p=n in q,p||(q.setAttribute(n,"return;"),p=typeof q[n]=="function"),b[o+"Bubbles"]=p;k.removeChild(q),k=g=h=j=q=i=null,f(function(){var a,d,e,g,h,i,j,k,m,n,o,r=c.getElementsByTagName("body")[0];!r||(j=1,k="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",m="visibility:hidden;border:0;",n="style='"+k+"border:5px solid #000;padding:0;'",o="<div "+n+"><div></div></div>"+"<table "+n+" cellpadding='0' cellspacing='0'>"+"<tr><td></td></tr></table>",a=c.createElement("div"),a.style.cssText=m+"width:0;height:0;position:static;top:0;margin-top:"+j+"px",r.insertBefore(a,r.firstChild),q=c.createElement("div"),a.appendChild(q),q.innerHTML="<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>",l=q.getElementsByTagName("td"),p=l[0].offsetHeight===0,l[0].style.display="",l[1].style.display="none",b.reliableHiddenOffsets=p&&l[0].offsetHeight===0,q.innerHTML="",q.style.width=q.style.paddingLeft="1px",f.boxModel=b.boxModel=q.offsetWidth===2,typeof q.style.zoom!="undefined"&&(q.style.display="inline",q.style.zoom=1,b.inlineBlockNeedsLayout=q.offsetWidth===2,q.style.display="",q.innerHTML="<div style='width:4px;'></div>",b.shrinkWrapBlocks=q.offsetWidth!==2),q.style.cssText=k+m,q.innerHTML=o,d=q.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,i={doesNotAddBorder:e.offsetTop!==5,doesAddBorderForTableAndCells:h.offsetTop===5},e.style.position="fixed",e.style.top="20px",i.fixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",i.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,i.doesNotIncludeMarginInBodyOffset=r.offsetTop!==j,r.removeChild(a),q=a=null,f.extend(b,i))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e<g;e++)delete d[b[e]];if(!(c?m:f.isEmptyObject)(d))return}}if(!c){delete j[k].data;if(!m(j[k]))return}f.support.deleteExpando||!j.setInterval?delete j[k]:j[k]=null,i&&(f.support.deleteExpando?delete a[h]:a.removeAttribute?a.removeAttribute(h):a[h]=null)}},_data:function(a,b,c){return f.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=f.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),f.fn.extend({data:function(a,c){var d,e,g,h=null;if(typeof a=="undefined"){if(this.length){h=f.data(this[0]);if(this[0].nodeType===1&&!f._data(this[0],"parsedAttrs")){e=this[0].attributes;for(var i=0,j=e.length;i<j;i++)g=e[i].name,g.indexOf("data-")===0&&(g=f.camelCase(g.substring(5)),l(this[0],g,h[g]));f._data(this[0],"parsedAttrs",!0)}}return h}if(typeof a=="object")return this.each(function(){f.data(this,a)});d=a.split("."),d[1]=d[1]?"."+d[1]:"";if(c===b){h=this.triggerHandler("getData"+d[1]+"!",[d[0]]),h===b&&this.length&&(h=f.data(this[0],a),h=l(this[0],a,h));return h===b&&d[1]?this.data(d[0]):h}return this.each(function(){var b=f(this),e=[d[0],c];b.triggerHandler("setData"+d[1]+"!",e),f.data(this,a,c),b.triggerHandler("changeData"+d[1]+"!",e)})},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||"fx")+"mark",f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||"fx";var d=c+"mark",e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,"mark"))}},queue:function(a,b,c){var d;if(a){b=(b||"fx")+"queue",d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e={};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),f._data(a,b+".run",e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+"queue "+b+".run",!0),n(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){typeof a!="string"&&(c=a,a="fx");if(c===b)return f.queue(this[0],a);return this.each(function(){var b=f.queue(this,a,c);a==="fx"&&b[0]!=="inprogress"&&f.dequeue(this,a)})},dequeue:function(a){return this.each(function(){f.dequeue(this,a)})},delay:function(a,b){a=f.fx?f.fx.speeds[a]||a:a,b=b||"fx";return this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){function m(){--h||d.resolveWith(e,[e])}typeof a!="string"&&(c=a,a=b),a=a||"fx";var d=f.Deferred(),e=this,g=e.length,h=1,i=a+"defer",j=a+"queue",k=a+"mark",l;while(g--)if(l=f.data(e[g],i,b,!0)||(f.data(e[g],j,b,!0)||f.data(e[g],k,b,!0))&&f.data(e[g],i,f.Callbacks("once memory"),!0))h++,l.add(m);m();return d.promise()}});var o=/[\n\t\r]/g,p=/\s+/,q=/\r/g,r=/^(?:button|input)$/i,s=/^(?:button|input|object|select|textarea)$/i,t=/^a(?:rea)?$/i,u=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,v=f.support.getSetAttribute,w,x,y;f.fn.extend({attr:function(a,b){return f.access(this,a,b,!0,f.attr)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,a,b,!0,f.prop)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this},removeClass:function(a){var c,d,e,g,h,i,j;if(f.isFunction(a))return this.each(function(b){f(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(p);for(d=0,e=this.length;d<e;d++){g=this[d];if(g.nodeType===1&&g.className)if(a){h=(" "+g.className+" ").replace(o," ");for(i=0,j=c.length;i<j;i++)h=h.replace(" "+c[i]+" "," ");g.className=f.trim(h)}else g.className=""}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";if(f.isFunction(a))return this.each(function(c){f(this).toggleClass(a.call(this,c,this.className,b),b)});return this.each(function(){if(c==="string"){var e,g=0,h=f(this),i=b,j=a.split(p);while(e=j[g++])i=d?i:!h.hasClass(e),h[i?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&f._data(this,"__className__",this.className),this.className=this.className||a===!1?"":f._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ",c=0,d=this.length;for(;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(o," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c<d;c++){e=i[c];if(e.selected&&(f.support.optDisabled?!e.disabled:e.getAttribute("disabled")===null)&&(!e.parentNode.disabled||!f.nodeName(e.parentNode,"optgroup"))){b=f(e).val();if(j)return b;h.push(b)}}if(j&&!h.length&&i.length)return f(i[g]).val();return h},set:function(a,b){var c=f.makeArray(b);f(a).find("option").each(function(){this.selected=f.inArray(f(this).val(),c)>=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;h<g;h++)e=d[h],e&&(c=f.propFix[e]||e,f.attr(a,e,""),a.removeAttribute(v?e:c),u.test(e)&&c in a&&(a[c]=!1))}},attrHooks:{type:{set:function(a,b){if(r.test(a.nodeName)&&a.parentNode)f.error("type property can't be changed");else if(!f.support.radioValue&&b==="radio"&&f.nodeName(a,"input")){var c=a.value;a.setAttribute("type",b),c&&(a.value=c);return b}}},value:{get:function(a,b){if(w&&f.nodeName(a,"button"))return w.get(a,b);return b in a?a.value:null},set:function(a,b,c){if(w&&f.nodeName(a,"button"))return w.set(a,b,c);a.value=b}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(a,c,d){var e,g,h,i=a.nodeType;if(!!a&&i!==3&&i!==8&&i!==2){h=i!==1||!f.isXMLDoc(a),h&&(c=f.propFix[c]||c,g=f.propHooks[c]);return d!==b?g&&"set"in g&&(e=g.set(a,d,c))!==b?e:a[c]=d:g&&"get"in g&&(e=g.get(a,c))!==null?e:a[c]}},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):s.test(a.nodeName)||t.test(a.nodeName)&&a.href?0:b}}}}),f.attrHooks.tabindex=f.propHooks.tabIndex,x={get:function(a,c){var d,e=f.prop(a,c);return e===!0||typeof e!="boolean"&&(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;b===!1?f.removeAttr(a,c):(d=f.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase()));return c}},v||(y={name:!0,id:!0},w=f.valHooks.button={get:function(a,c){var d;d=a.getAttributeNode(c);return d&&(y[c]?d.nodeValue!=="":d.specified)?d.nodeValue:b},set:function(a,b,d){var e=a.getAttributeNode(d);e||(e=c.createAttribute(d),a.setAttributeNode(e));return e.nodeValue=b+""}},f.attrHooks.tabindex.set=w.set,f.each(["width","height"],function(a,b){f.attrHooks[b]=f.extend(f.attrHooks[b],{set:function(a,c){if(c===""){a.setAttribute(b,"auto");return c}}})}),f.attrHooks.contenteditable={get:w.get,set:function(a,b,c){b===""&&(b="false"),w.set(a,b,c)}}),f.support.hrefNormalized||f.each(["href","src","width","height"],function(a,c){f.attrHooks[c]=f.extend(f.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),f.support.style||(f.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),f.support.optSelected||(f.propHooks.selected=f.extend(f.propHooks.selected,{get:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex);return null}})),f.support.enctype||(f.propFix.enctype="encoding"),f.support.checkOn||f.each(["radio","checkbox"],function(){f.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),f.each(["radio","checkbox"],function(){f.valHooks[this]=f.extend(f.valHooks[this],{set:function(a,b){if(f.isArray(b))return a.checked=f.inArray(f(a).val(),b)>=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/\bhover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function(a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")};
+f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k<c.length;k++){l=A.exec(c[k])||[],m=l[1],n=(l[2]||"").split(".").sort(),s=f.event.special[m]||{},m=(g?s.delegateType:s.bindType)||m,s=f.event.special[m]||{},o=f.extend({type:m,origType:l[1],data:e,handler:d,guid:d.guid,selector:g,quick:G(g),namespace:n.join(".")},p),r=j[m];if(!r){r=j[m]=[],r.delegateCount=0;if(!s.setup||s.setup.call(a,e,n,i)===!1)a.addEventListener?a.addEventListener(m,i,!1):a.attachEvent&&a.attachEvent("on"+m,i)}s.add&&(s.add.call(a,o),o.handler.guid||(o.handler.guid=d.guid)),g?r.splice(r.delegateCount++,0,o):r.push(o),f.event.global[m]=!0}a=null}},global:{},remove:function(a,b,c,d,e){var g=f.hasData(a)&&f._data(a),h,i,j,k,l,m,n,o,p,q,r,s;if(!!g&&!!(o=g.events)){b=f.trim(I(b||"")).split(" ");for(h=0;h<b.length;h++){i=A.exec(b[h])||[],j=k=i[1],l=i[2];if(!j){for(j in o)f.event.remove(a,j+b[h],c,d,!0);continue}p=f.event.special[j]||{},j=(d?p.delegateType:p.bindType)||j,r=o[j]||[],m=r.length,l=l?new RegExp("(^|\\.)"+l.split(".").sort().join("\\.(?:.*\\.)?")+"(\\.|$)"):null;for(n=0;n<r.length;n++)s=r[n],(e||k===s.origType)&&(!c||c.guid===s.guid)&&(!l||l.test(s.namespace))&&(!d||d===s.selector||d==="**"&&s.selector)&&(r.splice(n--,1),s.selector&&r.delegateCount--,p.remove&&p.remove.call(a,s));r.length===0&&m!==r.length&&((!p.teardown||p.teardown.call(a,l)===!1)&&f.removeEvent(a,j,g.handle),delete o[j])}f.isEmptyObject(o)&&(q=g.handle,q&&(q.elem=null),f.removeData(a,["events","handle"],!0))}},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,e,g){if(!e||e.nodeType!==3&&e.nodeType!==8){var h=c.type||c,i=[],j,k,l,m,n,o,p,q,r,s;if(E.test(h+f.event.triggered))return;h.indexOf("!")>=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;l<r.length&&!c.isPropagationStopped();l++)m=r[l][0],c.type=r[l][1],q=(f._data(m,"events")||{})[c.type]&&f._data(m,"handle"),q&&q.apply(m,d),q=o&&m[o],q&&f.acceptData(m)&&q.apply(m,d)===!1&&c.preventDefault();c.type=h,!g&&!c.isDefaultPrevented()&&(!p._default||p._default.apply(e.ownerDocument,d)===!1)&&(h!=="click"||!f.nodeName(e,"a"))&&f.acceptData(e)&&o&&e[h]&&(h!=="focus"&&h!=="blur"||c.target.offsetWidth!==0)&&!f.isWindow(e)&&(n=e[o],n&&(e[o]=null),f.event.triggered=h,e[h](),f.event.triggered=b,n&&(e[o]=n));return c.result}},dispatch:function(c){c=f.event.fix(c||a.event);var d=(f._data(this,"events")||{})[c.type]||[],e=d.delegateCount,g=[].slice.call(arguments,0),h=!c.exclusive&&!c.namespace,i=[],j,k,l,m,n,o,p,q,r,s,t;g[0]=c,c.delegateTarget=this;if(e&&!c.target.disabled&&(!c.button||c.type!=="click")){m=f(this),m.context=this.ownerDocument||this;for(l=c.target;l!=this;l=l.parentNode||this){o={},q=[],m[0]=l;for(j=0;j<e;j++)r=d[j],s=r.selector,o[s]===b&&(o[s]=r.quick?H(l,r.quick):m.is(s)),o[s]&&q.push(r);q.length&&i.push({elem:l,matches:q})}}d.length>e&&i.push({elem:this,matches:d.slice(e)});for(j=0;j<i.length&&!c.isPropagationStopped();j++){p=i[j],c.currentTarget=p.elem;for(k=0;k<p.matches.length&&!c.isImmediatePropagationStopped();k++){r=p.matches[k];if(h||!c.namespace&&!r.namespace||c.namespace_re&&c.namespace_re.test(r.namespace))c.data=r.data,c.handleObj=r,n=((f.event.special[r.origType]||{}).handle||r.handler).apply(p.elem,g),n!==b&&(c.result=n,n===!1&&(c.preventDefault(),c.stopPropagation()))}}return c.result},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){a.which==null&&(a.which=b.charCode!=null?b.charCode:b.keyCode);return a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,d){var e,f,g,h=d.button,i=d.fromElement;a.pageX==null&&d.clientX!=null&&(e=a.target.ownerDocument||c,f=e.documentElement,g=e.body,a.pageX=d.clientX+(f&&f.scrollLeft||g&&g.scrollLeft||0)-(f&&f.clientLeft||g&&g.clientLeft||0),a.pageY=d.clientY+(f&&f.scrollTop||g&&g.scrollTop||0)-(f&&f.clientTop||g&&g.clientTop||0)),!a.relatedTarget&&i&&(a.relatedTarget=i===a.target?d.toElement:i),!a.which&&h!==b&&(a.which=h&1?1:h&2?3:h&4?2:0);return a}},fix:function(a){if(a[f.expando])return a;var d,e,g=a,h=f.event.fixHooks[a.type]||{},i=h.props?this.props.concat(h.props):this.props;a=f.Event(g);for(d=i.length;d;)e=i[--d],a[e]=g[e];a.target||(a.target=g.srcElement||c),a.target.nodeType===3&&(a.target=a.target.parentNode),a.metaKey===b&&(a.metaKey=a.ctrlKey);return h.filter?h.filter(a,g):a},special:{ready:{setup:f.bindReady},load:{noBubble:!0},focus:{delegateType:"focusin"},blur:{delegateType:"focusout"},beforeunload:{setup:function(a,b,c){f.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}},simulate:function(a,b,c,d){var e=f.extend(new f.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?f.event.trigger(e,null,b):f.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},f.event.handle=f.event.dispatch,f.removeEvent=c.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){a.detachEvent&&a.detachEvent("on"+b,c)},f.Event=function(a,b){if(!(this instanceof f.Event))return new f.Event(a,b);a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?K:J):this.type=a,b&&f.extend(this,b),this.timeStamp=a&&a.timeStamp||f.now(),this[f.expando]=!0},f.Event.prototype={preventDefault:function(){this.isDefaultPrevented=K;var a=this.originalEvent;!a||(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){this.isPropagationStopped=K;var a=this.originalEvent;!a||(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=K,this.stopPropagation()},isDefaultPrevented:J,isPropagationStopped:J,isImmediatePropagationStopped:J},f.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){f.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c=this,d=a.relatedTarget,e=a.handleObj,g=e.selector,h;if(!d||d!==c&&!f.contains(c,d))a.type=e.origType,h=e.handler.apply(this,arguments),a.type=b;return h}}}),f.support.submitBubbles||(f.event.special.submit={setup:function(){if(f.nodeName(this,"form"))return!1;f.event.add(this,"click._submit keypress._submit",function(a){var c=a.target,d=f.nodeName(c,"input")||f.nodeName(c,"button")?c.form:b;d&&!d._submit_attached&&(f.event.add(d,"submit._submit",function(a){this.parentNode&&!a.isTrigger&&f.event.simulate("submit",this.parentNode,a,!0)}),d._submit_attached=!0)})},teardown:function(){if(f.nodeName(this,"form"))return!1;f.event.remove(this,"._submit")}}),f.support.changeBubbles||(f.event.special.change={setup:function(){if(z.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")f.event.add(this,"propertychange._change",function(a){a.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),f.event.add(this,"click._change",function(a){this._just_changed&&!a.isTrigger&&(this._just_changed=!1,f.event.simulate("change",this,a,!0))});return!1}f.event.add(this,"beforeactivate._change",function(a){var b=a.target;z.test(b.nodeName)&&!b._change_attached&&(f.event.add(b,"change._change",function(a){this.parentNode&&!a.isSimulated&&!a.isTrigger&&f.event.simulate("change",this.parentNode,a,!0)}),b._change_attached=!0)})},handle:function(a){var b=a.target;if(this!==b||a.isSimulated||a.isTrigger||b.type!=="radio"&&b.type!=="checkbox")return a.handleObj.handler.apply(this,arguments)},teardown:function(){f.event.remove(this,"._change");return z.test(this.nodeName)}}),f.support.focusinBubbles||f.each({focus:"focusin",blur:"focusout"},function(a,b){var d=0,e=function(a){f.event.simulate(b,a.target,f.event.fix(a),!0)};f.event.special[b]={setup:function(){d++===0&&c.addEventListener(a,e,!0)},teardown:function(){--d===0&&c.removeEventListener(a,e,!0)}}}),f.fn.extend({on:function(a,c,d,e,g){var h,i;if(typeof a=="object"){typeof c!="string"&&(d=c,c=b);for(i in a)this.on(i,c,d,a[i],g);return this}d==null&&e==null?(e=c,d=c=b):e==null&&(typeof c=="string"?(e=d,d=b):(e=d,d=c,c=b));if(e===!1)e=J;else if(!e)return this;g===1&&(h=e,e=function(a){f().off(a);return h.apply(this,arguments)},e.guid=h.guid||(h.guid=f.guid++));return this.each(function(){f.event.add(this,a,e,d,c)})},one:function(a,b,c,d){return this.on.call(this,a,b,c,d,1)},off:function(a,c,d){if(a&&a.preventDefault&&a.handleObj){var e=a.handleObj;f(a.delegateTarget).off(e.namespace?e.type+"."+e.namespace:e.type,e.selector,e.handler);return this}if(typeof a=="object"){for(var g in a)this.off(g,c,a[g]);return this}if(c===!1||typeof c=="function")d=c,c=b;d===!1&&(d=J);return this.each(function(){f.event.remove(this,a,d,c)})},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},live:function(a,b,c){f(this.context).on(a,this.selector,b,c);return this},die:function(a,b){f(this.context).off(a,this.selector||"**",b);return this},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return arguments.length==1?this.off(a,"**"):this.off(b,a,c)},trigger:function(a,b){return this.each(function(){f.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return f.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f._data(this,"lastToggle"+a.guid)||0)%d;f._data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),f.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){f.fn[b]=function(a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}if(j.nodeType===1){g||(j[d]=c,j.sizset=h);if(typeof b!="string"){if(j===b){k=!0;break}}else if(m.filter(b,[j]).length>0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}j.nodeType===1&&!g&&(j[d]=c,j.sizset=h);if(j.nodeName.toLowerCase()===b){k=j;break}j=j[a]}e[h]=k}}}var a=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b<a.length;b++)a[b]===a[b-1]&&a.splice(b--,1)}return a},m.matches=function(a,b){return m(a,null,null,b)},m.matchesSelector=function(a,b){return m(b,null,null,[a]).length>0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e<f;e++){h=o.order[e];if(g=o.leftMatch[h].exec(a)){i=g[1],g.splice(1,1);if(i.substr(i.length-1)!=="\\"){g[1]=(g[1]||"").replace(j,""),d=o.find[h](g,b,c);if(d!=null){a=a.replace(o.match[h],"");break}}}}d||(d=typeof b.getElementsByTagName!="undefined"?b.getElementsByTagName("*"):[]);return{set:d,expr:a}},m.filter=function(a,c,d,e){var f,g,h,i,j,k,l,n,p,q=a,r=[],s=c,t=c&&c[0]&&m.isXML(c[0]);while(a&&c.length){for(h in o.filter)if((f=o.leftMatch[h].exec(a))!=null&&f[2]){k=o.filter[h],l=f[1],g=!1,f.splice(1,1);if(l.substr(l.length-1)==="\\")continue;s===r&&(r=[]);if(o.preFilter[h]){f=o.preFilter[h](f,s,d,r,e,t);if(!f)g=i=!0;else if(f===!0)continue}if(f)for(n=0;(j=s[n])!=null;n++)j&&(i=k(j,f,n,s),p=e^i,d&&i!=null?p?g=!0:s[n]=!1:p&&(r.push(j),g=!0));if(i!==b){d||(s=r),a=a.replace(o.match[h],"");if(!g)return[];break}}if(a===q)if(g==null)m.error(a);else break;q=a}return s},m.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)};var n=m.getText=function(a){var b,c,d=a.nodeType,e="";if(d){if(d===1||d===9){if(typeof a.textContent=="string")return a.textContent;if(typeof a.innerText=="string")return a.innerText.replace(k,"");for(a=a.firstChild;a;a=a.nextSibling)e+=n(a)}else if(d===3||d===4)return a.nodeValue}else for(b=0;c=a[b];b++)c.nodeType!==8&&(e+=n(c));return e},o=m.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAttribute("type")}},relative:{"+":function(a,b){var c=typeof b=="string",d=c&&!l.test(b),e=c&&!d;d&&(b=b.toLowerCase());for(var f=0,g=a.length,h;f<g;f++)if(h=a[f]){while((h=h.previousSibling)&&h.nodeType!==1);a[f]=e||h&&h.nodeName.toLowerCase()===b?h||!1:h===b}e&&m.filter(b,a,!0)},">":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e<f;e++){c=a[e];if(c){var g=c.parentNode;a[e]=g.nodeName.toLowerCase()===b?g:!1}}}else{for(;e<f;e++)c=a[e],c&&(a[e]=d?c.parentNode:c.parentNode===b);d&&m.filter(b,a,!0)}},"":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("parentNode",b,f,a,d,c)},"~":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("previousSibling",b,f,a,d,c)}},find:{ID:function(a,b,c){if(typeof b.getElementById!="undefined"&&!c){var d=b.getElementById(a[1]);return d&&d.parentNode?[d]:[]}},NAME:function(a,b){if(typeof b.getElementsByName!="undefined"){var c=[],d=b.getElementsByName(a[1]);for(var e=0,f=d.length;e<f;e++)d[e].getAttribute("name")===a[1]&&c.push(d[e]);return c.length===0?null:c}},TAG:function(a,b){if(typeof b.getElementsByTagName!="undefined")return b.getElementsByTagName(a[1])}},preFilter:{CLASS:function(a,b,c,d,e,f){a=" "+a[1].replace(j,"")+" ";if(f)return a;for(var g=0,h;(h=b[g])!=null;g++)h&&(e^(h.className&&(" "+h.className+" ").replace(/[\t\n\r]/g," ").indexOf(a)>=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return b<c[3]-0},gt:function(a,b,c){return b>c[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h<i;h++)if(g[h]===a)return!1;return!0}m.error(e)},CHILD:function(a,b){var c,e,f,g,h,i,j,k=b[1],l=a;switch(k){case"only":case"first":while(l=l.previousSibling)if(l.nodeType===1)return!1;if(k==="first")return!0;l=a;case"last":while(l=l.nextSibling)if(l.nodeType===1)return!1;return!0;case"nth":c=b[2],e=b[3];if(c===1&&e===0)return!0;f=b[0],g=a.parentNode;if(g&&(g[d]!==f||!a.nodeIndex)){i=0;for(l=g.firstChild;l;l=l.nextSibling)l.nodeType===1&&(l.nodeIndex=++i);g[d]=f}j=a.nodeIndex-e;return c===0?j===0:j%c===0&&j/c>=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c<e;c++)d.push(a[c]);else for(;a[c];c++)d.push(a[c]);return d}}var u,v;c.documentElement.compareDocumentPosition?u=function(a,b){if(a===b){h=!0;return 0}if(!a.compareDocumentPosition||!b.compareDocumentPosition)return a.compareDocumentPosition?-1:1;return a.compareDocumentPosition(b)&4?-1:1}:(u=function(a,b){if(a===b){h=!0;return 0}if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],f=[],g=a.parentNode,i=b.parentNode,j=g;if(g===i)return v(a,b);if(!g)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)f.unshift(j),j=j.parentNode;c=e.length,d=f.length;for(var k=0;k<c&&k<d;k++)if(e[k]!==f[k])return v(e[k],f[k]);return k===c?v(a,f[k],-1):v(e[k],b,1)},v=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),function(){var a=c.createElement("div"),d="script"+(new Date).getTime(),e=c.documentElement;a.innerHTML="<a name='"+d+"'/>",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="<p class='TEST'></p>";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class='test e'></div><div class='test'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h<i;h++)m(a,g[h],e,c);return m.filter(f,e)};m.attr=f.attr,m.selectors.attrMap={},f.find=m,f.expr=m.selectors,f.expr[":"]=f.expr.filters,f.unique=m.uniqueSort,f.text=m.getText,f.isXMLDoc=m.isXML,f.contains=m.contains}();var L=/Until$/,M=/^(?:parents|prevUntil|prevAll)/,N=/,/,O=/^.[^:#\[\.,]*$/,P=Array.prototype.slice,Q=f.expr.match.POS,R={children:!0,contents:!0,next:!0,prev:!0};f.fn.extend({find:function(a){var b=this,c,d;if(typeof a!="string")return f(a).filter(function(){for(c=0,d=b.length;c<d;c++)if(f.contains(b[c],this))return!0});var e=this.pushStack("","find",a),g,h,i;for(c=0,d=this.length;c<d;c++){g=e.length,f.find(a,this[c],e);if(c>0)for(h=g;h<e.length;h++)for(i=0;i<g;i++)if(e[i]===e[h]){e.splice(h--,1);break}}return e},has:function(a){var b=f(a);return this.filter(function(){for(var a=0,c=b.length;a<c;a++)if(f.contains(this,b[a]))return!0})},not:function(a){return this.pushStack(T(this,a,!1),"not",a)},filter:function(a){return this.pushStack(T(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?Q.test(a)?f(a,this.context).index(this[0])>=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d<a.length;d++)f(g).is(a[d])&&c.push({selector:a[d],elem:g,level:h});g=g.parentNode,h++}return c}var i=Q.test(a)||typeof a!="string"?f(a,b||this.context):0;for(d=0,e=this.length;d<e;d++){g=this[d];while(g){if(i?i.index(g)>-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/<tbody/i,_=/<|&#?\w+;/,ba=/<(?:script|style)/i,bb=/<(?:script|object|embed|option|style)/i,bc=new RegExp("<(?:"+V+")","i"),bd=/checked\s*(?:[^=]|=\s*.checked.)/i,be=/\/(java|ecma)script/i,bf=/^\s*<!(?:\[CDATA\[|\-\-)/,bg={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div<div>","</div>"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function()
+{for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1></$2>");try{for(var c=0,d=this.length;c<d;c++)this[c].nodeType===1&&(f.cleanData(this[c].getElementsByTagName("*")),this[c].innerHTML=a)}catch(e){this.empty().append(a)}}else f.isFunction(a)?this.each(function(b){var c=f(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(f.isFunction(a))return this.each(function(b){var c=f(this),d=c.html();c.replaceWith(a.call(this,b,d))});typeof a!="string"&&(a=f(a).detach());return this.each(function(){var b=this.nextSibling,c=this.parentNode;f(this).remove(),b?f(b).before(a):f(c).append(a)})}return this.length?this.pushStack(f(f.isFunction(a)?a():a),"replaceWith",a):this},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){var e,g,h,i,j=a[0],k=[];if(!f.support.checkClone&&arguments.length===3&&typeof j=="string"&&bd.test(j))return this.each(function(){f(this).domManip(a,c,d,!0)});if(f.isFunction(j))return this.each(function(e){var g=f(this);a[0]=j.call(this,e,c?g.html():b),g.domManip(a,c,d)});if(this[0]){i=j&&j.parentNode,f.support.parentNode&&i&&i.nodeType===11&&i.childNodes.length===this.length?e={fragment:i}:e=f.buildFragment(a,this,k),h=e.fragment,h.childNodes.length===1?g=h=h.firstChild:g=h.firstChild;if(g){c=c&&f.nodeName(g,"tr");for(var l=0,m=this.length,n=m-1;l<m;l++)d.call(c?bi(this[l],g):this[l],e.cacheable||m>1&&l<n?f.clone(h,!0,!0):h)}k.length&&f.each(k,bp)}return this}}),f.buildFragment=function(a,b,d){var e,g,h,i,j=a[0];b&&b[0]&&(i=b[0].ownerDocument||b[0]),i.createDocumentFragment||(i=c),a.length===1&&typeof j=="string"&&j.length<512&&i===c&&j.charAt(0)==="<"&&!bb.test(j)&&(f.support.checkClone||!bd.test(j))&&(f.support.html5Clone||!bc.test(j))&&(g=!0,h=f.fragments[j],h&&h!==1&&(e=h)),e||(e=i.createDocumentFragment(),f.clean(a,i,e,d)),g&&(f.fragments[j]=h?e:1);return{fragment:e,cacheable:g}},f.fragments={},f.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){f.fn[a]=function(c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||!bc.test("<"+a.nodeName)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1></$2>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=bg[l]||bg._default,n=m[0],o=b.createElement("div");b===c?bh.appendChild(o):U(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]==="<table>"&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i<r;i++)bn(k[i]);else bn(k);k.nodeType?h.push(k):h=f.merge(h,k)}if(d){g=function(a){return!a.type||be.test(a.type)};for(j=0;h[j];j++)if(e&&f.nodeName(h[j],"script")&&(!h[j].type||h[j].type.toLowerCase()==="text/javascript"))e.push(h[j].parentNode?h[j].parentNode.removeChild(h[j]):h[j]);else{if(h[j].nodeType===1){var s=f.grep(h[j].getElementsByTagName("script"),g);h.splice.apply(h,[j+1,0].concat(s))}d.appendChild(h[j])}}return h},cleanData:function(a){var b,c,d=f.cache,e=f.event.special,g=f.support.deleteExpando;for(var h=0,i;(i=a[h])!=null;h++){if(i.nodeName&&f.noData[i.nodeName.toLowerCase()])continue;c=i[f.expando];if(c){b=d[c];if(b&&b.events){for(var j in b.events)e[j]?f.event.remove(i,j):f.removeEvent(i,j,b.handle);b.handle&&(b.handle.elem=null)}g?delete i[f.expando]:i.removeAttribute&&i.removeAttribute(f.expando),delete d[c]}}}});var bq=/alpha\([^)]*\)/i,br=/opacity=([^)]*)/,bs=/([A-Z]|^ms)/g,bt=/^-?\d+(?:px)?$/i,bu=/^-?\d/,bv=/^([\-+])=([\-+.\de]+)/,bw={position:"absolute",visibility:"hidden",display:"block"},bx=["Left","Right"],by=["Top","Bottom"],bz,bA,bB;f.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return f.access(this,a,c,!0,function(a,c,d){return d!==b?f.style(a,c,d):f.css(a,c)})},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bz(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=bv.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(bz)return bz(a,c)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]}}),f.curCSS=f.css,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){var e;if(c){if(a.offsetWidth!==0)return bC(a,b,d);f.swap(a,bw,function(){e=bC(a,b,d)});return e}},set:function(a,b){if(!bt.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return br.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bq,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bq.test(g)?g.replace(bq,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bz(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bA=function(a,b){var c,d,e;b=b.replace(bs,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b)));return c}),c.documentElement.currentStyle&&(bB=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bt.test(f)&&bu.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bz=bA||bB,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bD=/%20/g,bE=/\[\]$/,bF=/\r?\n/g,bG=/#.*$/,bH=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bI=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bJ=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bK=/^(?:GET|HEAD)$/,bL=/^\/\//,bM=/\?/,bN=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bO=/^(?:select|textarea)/i,bP=/\s+/,bQ=/([?&])_=[^&]*/,bR=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bS=f.fn.load,bT={},bU={},bV,bW,bX=["*/"]+["*"];try{bV=e.href}catch(bY){bV=c.createElement("a"),bV.href="",bV=bV.href}bW=bR.exec(bV.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bS)return bS.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bN,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bO.test(this.nodeName)||bI.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bF,"\r\n")}}):{name:b.name,value:c.replace(bF,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b_(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b_(a,b);return a},ajaxSettings:{url:bV,isLocal:bJ.test(bW[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bX},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bZ(bT),ajaxTransport:bZ(bU),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cb(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cc(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bG,"").replace(bL,bW[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bP),d.crossDomain==null&&(r=bR.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bW[1]&&r[2]==bW[2]&&(r[3]||(r[1]==="http:"?80:443))==(bW[3]||(bW[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),b$(bT,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bK.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bM.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bQ,"$1_="+x);d.url=y+(y===d.url?(bM.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bX+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=b$(bU,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cd=f.now(),ce=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cd++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ce.test(b.url)||e&&ce.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ce,l),b.url===j&&(e&&(k=k.replace(ce,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cf=a.ActiveXObject?function(){for(var a in ch)ch[a](0,1)}:!1,cg=0,ch;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ci()||cj()}:ci,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cf&&delete ch[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cg,cf&&(ch||(ch={},f(a).unload(cf)),ch[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var ck={},cl,cm,cn=/^(?:toggle|show|hide)$/,co=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cp,cq=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cr;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cu("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),e===""&&f.css(d,"display")==="none"&&f._data(d,"olddisplay",cv(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(cu("hide",3),a,b,c);var d,e,g=0,h=this.length;for(;g<h;g++)d=this[g],d.style&&(e=f.css(d,"display"),e!=="none"&&!f._data(d,"olddisplay")&&f._data(d,"olddisplay",e));for(g=0;g<h;g++)this[g].style&&(this[g].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(cu("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cv(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cn.test(h)?(o=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),o?(f._data(this,"toggle"+i,o==="show"?"hide":"show"),j[o]()):j[h]()):(k=co.exec(h),l=j.cur(),k?(m=parseFloat(k[2]),n=k[3]||(f.cssNumber[i]?"":"px"),n!=="px"&&(f.style(this,i,(m||1)+n),l=(m||1)/j.cur()*l,f.style(this,i,l+n)),k[1]&&(m=(k[1]==="-="?-1:1)*m+l),j.custom(l,m,n)):j.custom(l,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)},stop:function(a,c,d){typeof a!="string"&&(d=c,c=a,a=b),c&&a!==!1&&this.queue(a||"fx",[]);return this.each(function(){function h(a,b,c){var e=b[c];f.removeData(a,c,!0),e.stop(d)}var b,c=!1,e=f.timers,g=f._data(this);d||f._unmark(!0,this);if(a==null)for(b in g)g[b]&&g[b].stop&&b.indexOf(".run")===b.length-4&&h(this,g,b);else g[b=a+".run"]&&g[b].stop&&h(this,g,b);for(b=e.length;b--;)e[b].elem===this&&(a==null||e[b].queue===a)&&(d?e[b](!0):e[b].saveState(),c=!0,e.splice(b,1));(!d||!c)&&f.dequeue(this,a)})}}),f.each({slideDown:cu("show",1),slideUp:cu("hide",1),slideToggle:cu("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default;if(d.queue==null||d.queue===!0)d.queue="fx";d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue?f.dequeue(this,d.queue):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,c,d){function h(a){return e.step(a)}var e=this,g=f.fx;this.startTime=cr||cs(),this.end=c,this.now=this.start=a,this.pos=this.state=0,this.unit=d||this.unit||(f.cssNumber[this.prop]?"":"px"),h.queue=this.options.queue,h.elem=this.elem,h.saveState=function(){e.options.hide&&f._data(e.elem,"fxshow"+e.prop)===b&&f._data(e.elem,"fxshow"+e.prop,e.start)},h()&&f.timers.push(h)&&!cp&&(cp=setInterval(g.tick,g.interval))},show:function(){var a=f._data(this.elem,"fxshow"+this.prop);this.options.orig[this.prop]=a||f.style(this.elem,this.prop),this.options.show=!0,a!==b?this.custom(this.cur(),a):this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f._data(this.elem,"fxshow"+this.prop)||f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b,c,d,e=cr||cs(),g=!0,h=this.elem,i=this.options;if(a||e>=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c<b.length;c++)a=b[c],!a()&&b[c]===a&&b.splice(c--,1);b.length||f.fx.stop()},interval:13,stop:function(){clearInterval(cp),cp=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=a.now+a.unit:a.elem[a.prop]=a.now}}}),f.each(["width","height"],function(a,b){f.fx.step[b]=function(a){f.style(a.elem,b,Math.max(0,a.now)+a.unit)}}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cw=/^t(?:able|d|h)$/i,cx=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?f.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(d){}var e=b.ownerDocument,g=e.documentElement;if(!c||!f.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=e.body,i=cy(e),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||f.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||f.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:f.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);var c,d=b.offsetParent,e=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(f.support.fixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===d&&(l+=b.offsetTop,m+=b.offsetLeft,f.support.doesNotAddBorder&&(!f.support.doesAddBorderForTableAndCells||!cw.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),e=d,d=b.offsetParent),f.support.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;f.support.fixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},f.offset={bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.support.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cy(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cy(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window); \ No newline at end of file
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/LICENCE b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/LICENCE
new file mode 100644
index 0000000000..5d56a81cb8
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/LICENCE
@@ -0,0 +1,26 @@
+/*
+ * index.css
+ * qmf.css
+ *
+ * Copyright (c) 2013, Fraser Adams
+ *
+ * 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.
+ *
+ */
+
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/index.css b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/index.css
new file mode 100644
index 0000000000..e6baccf862
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/index.css
@@ -0,0 +1,43 @@
+html
+{
+ background: black;
+}
+
+body
+{
+ position: absolute;
+
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ margin: 0;
+
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+
+ background: #bbb url(/qmf-ui/images/gradient.png) repeat-x;
+ background: -o-linear-gradient(top center, #fff 0%, #bbb 100%);
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #bbb));
+ background: -webkit-linear-gradient(top center, #fff 0%, #bbb 100%);
+ background: -ms-linear-gradient(top center, #fff 0%, #bbb 100%);
+ background: -moz-linear-gradient(top center, #fff 0%, #bbb 100%);
+}
+
+div.logo
+{
+ position: absolute;
+ top: 5%;
+ left: 0;
+ right: 0;
+ height: 114px;
+ margin: 0 35% 0 35%;
+
+ -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
+ filter: alpha(opacity=70);
+ opacity: 0.7;
+
+ background: transparent url(/qmf-ui/images/qpid-logo.png) center no-repeat;
+}
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/qmf.css b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/qmf.css
new file mode 100644
index 0000000000..918c4b5e22
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/css/qmf.css
@@ -0,0 +1,124 @@
+
+a.settings
+{
+ background: url(/qmf-ui/images/settings.png) no-repeat left;
+}
+
+a.brokers
+{
+ background: url(/qmf-ui/images/brokers.png) no-repeat left;
+}
+
+a.connections
+{
+ background: url(/qmf-ui/images/connections.png) no-repeat left;
+}
+
+a.exchanges
+{
+ background: url(/qmf-ui/images/exchanges.png) no-repeat left;
+}
+
+a.queues
+{
+ background: url(/qmf-ui/images/queues.png) no-repeat left;
+}
+
+a.links
+{
+ background: url(/qmf-ui/images/links.png) no-repeat left;
+}
+
+a.route-topology
+{
+ background: url(/qmf-ui/images/route-topology.png) no-repeat left;
+}
+
+a.events
+{
+ background: url(/qmf-ui/images/events.png) no-repeat left;
+}
+
+/* This style allows a simple alert banner to be displayed */
+div.alert
+{
+ position: fixed;
+ opacity: 0.6;
+
+ font-size: 30pt;
+ color: #d0d0d0;
+ background: red;
+
+ top: 45.5%;
+ left: 10%;
+ width: 80%;
+ text-align: center;
+
+ -o-transform: rotate(-45deg);
+ -ms-transform: rotate(-45deg);
+ -webkit-transform: rotate(-45deg);
+ -moz-transform: rotate(-45deg);
+
+ box-shadow: 5px 5px 5px #888;
+ z-index: 5;
+ display: none;
+
+ /* At it's only a few styles different just use <= IE8 css hack rather than a whole stylesheet */
+ position: relative\9;
+ background: url(/itablet/images/ie/red6.png) repeat\9;
+ top: 200px\9;
+}
+
+
+#splash
+{
+ position: absolute;
+
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ margin: 0;
+
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+
+ background: #bbb url(/qmf-ui/images/gradient.png) repeat-x;
+ background: -o-linear-gradient(top center, #fff 0%, #bbb 100%);
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #bbb));
+ background: -webkit-linear-gradient(top center, #fff 0%, #bbb 100%);
+ background: -ms-linear-gradient(top center, #fff 0%, #bbb 100%);
+ background: -moz-linear-gradient(top center, #fff 0%, #bbb 100%);
+
+ z-index: 100;
+}
+
+#splash div.logo
+{
+ position: absolute;
+ top: 5%;
+ left: 0;
+ right: 0;
+ height: 114px;
+ margin: 0 35% 0 35%;
+
+ -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
+ filter: alpha(opacity=70);
+ opacity: 0.7;
+
+ background: transparent url(/qmf-ui/images/qpid-logo.png) center no-repeat;
+}
+
+#splash div.loading
+{
+ position: absolute;
+ top: 70px;
+ left: 0;
+ right: 0;
+ height: 32px;
+
+ background: transparent url(/qmf-ui/images/loading.gif) center no-repeat;
+}
+
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/brokers.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/brokers.png
new file mode 100644
index 0000000000..72efa7ab11
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/brokers.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/connections.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/connections.png
new file mode 100644
index 0000000000..2e1d422d0a
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/connections.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/events.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/events.png
new file mode 100644
index 0000000000..1e5a7ee5ca
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/events.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/exchanges.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/exchanges.png
new file mode 100644
index 0000000000..5f15dbbfdc
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/exchanges.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/gradient.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/gradient.png
new file mode 100644
index 0000000000..260a05701f
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/gradient.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/links.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/links.png
new file mode 100644
index 0000000000..d8ad7af518
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/links.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/loading.gif b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/loading.gif
new file mode 100644
index 0000000000..3288d1035d
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/loading.gif
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/qpid-logo.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/qpid-logo.png
new file mode 100644
index 0000000000..d548b68245
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/qpid-logo.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/queues.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/queues.png
new file mode 100644
index 0000000000..4f72abfe50
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/queues.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/route-topology.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/route-topology.png
new file mode 100644
index 0000000000..c1b36d4077
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/route-topology.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/settings.png b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/settings.png
new file mode 100644
index 0000000000..6994d4a0d4
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/images/settings.png
Binary files differ
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/LICENCE b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/LICENCE
new file mode 100644
index 0000000000..91c70259c7
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/LICENCE
@@ -0,0 +1,63 @@
+/*
+ * qmf-ui.js
+ *
+ * Copyright (c) 2013, Fraser Adams
+ *
+ * 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.
+ *
+ */
+
+
+/*
+ * excanvas.js
+ *
+ * ExplorerCanvas - provides HTML5 canvas on IE
+ *
+ * note that this is using excanvas.js from http://explorercanvas.googlecode.com/svn/trunk/ as it happens that's
+ * more up to date than the version https://code.google.com/p/explorercanvas/downloads/list/excanvas_r3.zip which
+ * is the version one gets following the obvious path. Unfortunately excanvas_r3.zip has several bugs in drawImage()
+ * which affect the border radius rendering for IE7 canvas, the version from trunk fixes that....
+ *
+ * Google Open Source:
+ * <http://code.google.com>
+ * <opensource@google.com>
+ *
+ * Developers:
+ * Emil A Eklund <emil@eae.net>
+ * Erik Arvidsson <erik@eae.net>
+ * Glen Murphy <glen@glenmurphy.com>
+ *
+ * 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.
+ *
+ */
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/excanvas.js b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/excanvas.js
new file mode 100644
index 0000000000..a6d9ddf5fa
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/excanvas.js
@@ -0,0 +1,1416 @@
+// Copyright 2006 Google Inc.
+//
+// Licensed 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.
+
+
+// Known Issues:
+//
+// * Patterns only support repeat.
+// * Radial gradient are not implemented. The VML version of these look very
+// different from the canvas one.
+// * Clipping paths are not implemented.
+// * Coordsize. The width and height attribute have higher priority than the
+// width and height style values which isn't correct.
+// * Painting mode isn't implemented.
+// * Canvas width/height should is using content-box by default. IE in
+// Quirks mode will draw the canvas using border-box. Either change your
+// doctype to HTML5
+// (http://www.whatwg.org/specs/web-apps/current-work/#the-doctype)
+// or use Box Sizing Behavior from WebFX
+// (http://webfx.eae.net/dhtml/boxsizing/boxsizing.html)
+// * Non uniform scaling does not correctly scale strokes.
+// * Optimize. There is always room for speed improvements.
+
+// Only add this code if we do not already have a canvas implementation
+if (!document.createElement('canvas').getContext) {
+
+(function() {
+
+ // alias some functions to make (compiled) code shorter
+ var m = Math;
+ var mr = m.round;
+ var ms = m.sin;
+ var mc = m.cos;
+ var abs = m.abs;
+ var sqrt = m.sqrt;
+
+ // this is used for sub pixel precision
+ var Z = 10;
+ var Z2 = Z / 2;
+
+ var IE_VERSION = +navigator.userAgent.match(/MSIE ([\d.]+)?/)[1];
+
+ /**
+ * This funtion is assigned to the <canvas> elements as element.getContext().
+ * @this {HTMLElement}
+ * @return {CanvasRenderingContext2D_}
+ */
+ function getContext() {
+ return this.context_ ||
+ (this.context_ = new CanvasRenderingContext2D_(this));
+ }
+
+ var slice = Array.prototype.slice;
+
+ /**
+ * Binds a function to an object. The returned function will always use the
+ * passed in {@code obj} as {@code this}.
+ *
+ * Example:
+ *
+ * g = bind(f, obj, a, b)
+ * g(c, d) // will do f.call(obj, a, b, c, d)
+ *
+ * @param {Function} f The function to bind the object to
+ * @param {Object} obj The object that should act as this when the function
+ * is called
+ * @param {*} var_args Rest arguments that will be used as the initial
+ * arguments when the function is called
+ * @return {Function} A new function that has bound this
+ */
+ function bind(f, obj, var_args) {
+ var a = slice.call(arguments, 2);
+ return function() {
+ return f.apply(obj, a.concat(slice.call(arguments)));
+ };
+ }
+
+ function encodeHtmlAttribute(s) {
+ return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
+ }
+
+ function addNamespace(doc, prefix, urn) {
+ if (!doc.namespaces[prefix]) {
+ doc.namespaces.add(prefix, urn, '#default#VML');
+ }
+ }
+
+ function addNamespacesAndStylesheet(doc) {
+ addNamespace(doc, 'g_vml_', 'urn:schemas-microsoft-com:vml');
+ addNamespace(doc, 'g_o_', 'urn:schemas-microsoft-com:office:office');
+
+ // Setup default CSS. Only add one style sheet per document
+ if (!doc.styleSheets['ex_canvas_']) {
+ var ss = doc.createStyleSheet();
+ ss.owningElement.id = 'ex_canvas_';
+ ss.cssText = 'canvas{display:inline-block;overflow:hidden;' +
+ // default size is 300x150 in Gecko and Opera
+ 'text-align:left;width:300px;height:150px}';
+ }
+ }
+
+ // Add namespaces and stylesheet at startup.
+ addNamespacesAndStylesheet(document);
+
+ var G_vmlCanvasManager_ = {
+ init: function(opt_doc) {
+ var doc = opt_doc || document;
+ // Create a dummy element so that IE will allow canvas elements to be
+ // recognized.
+ doc.createElement('canvas');
+ doc.attachEvent('onreadystatechange', bind(this.init_, this, doc));
+ },
+
+ init_: function(doc) {
+ // find all canvas elements
+ var els = doc.getElementsByTagName('canvas');
+ for (var i = 0; i < els.length; i++) {
+ this.initElement(els[i]);
+ }
+ },
+
+ /**
+ * Public initializes a canvas element so that it can be used as canvas
+ * element from now on. This is called automatically before the page is
+ * loaded but if you are creating elements using createElement you need to
+ * make sure this is called on the element.
+ * @param {HTMLElement} el The canvas element to initialize.
+ * @return {HTMLElement} the element that was created.
+ */
+ initElement: function(el) {
+ if (!el.getContext) {
+ el.getContext = getContext;
+
+ // Add namespaces and stylesheet to document of the element.
+ addNamespacesAndStylesheet(el.ownerDocument);
+
+ // Remove fallback content. There is no way to hide text nodes so we
+ // just remove all childNodes. We could hide all elements and remove
+ // text nodes but who really cares about the fallback content.
+ el.innerHTML = '';
+
+ // do not use inline function because that will leak memory
+ el.attachEvent('onpropertychange', onPropertyChange);
+ el.attachEvent('onresize', onResize);
+
+ var attrs = el.attributes;
+ if (attrs.width && attrs.width.specified) {
+ // TODO: use runtimeStyle and coordsize
+ // el.getContext().setWidth_(attrs.width.nodeValue);
+ el.style.width = attrs.width.nodeValue + 'px';
+ } else {
+ el.width = el.clientWidth;
+ }
+ if (attrs.height && attrs.height.specified) {
+ // TODO: use runtimeStyle and coordsize
+ // el.getContext().setHeight_(attrs.height.nodeValue);
+ el.style.height = attrs.height.nodeValue + 'px';
+ } else {
+ el.height = el.clientHeight;
+ }
+ //el.getContext().setCoordsize_()
+ }
+ return el;
+ }
+ };
+
+ function onPropertyChange(e) {
+ var el = e.srcElement;
+
+ switch (e.propertyName) {
+ case 'width':
+ el.getContext().clearRect();
+ el.style.width = el.attributes.width.nodeValue + 'px';
+ // In IE8 this does not trigger onresize.
+ el.firstChild.style.width = el.clientWidth + 'px';
+ break;
+ case 'height':
+ el.getContext().clearRect();
+ el.style.height = el.attributes.height.nodeValue + 'px';
+ el.firstChild.style.height = el.clientHeight + 'px';
+ break;
+ }
+ }
+
+ function onResize(e) {
+ var el = e.srcElement;
+ if (el.firstChild) {
+ el.firstChild.style.width = el.clientWidth + 'px';
+ el.firstChild.style.height = el.clientHeight + 'px';
+ }
+ }
+
+ G_vmlCanvasManager_.init();
+
+ // precompute "00" to "FF"
+ var decToHex = [];
+ for (var i = 0; i < 16; i++) {
+ for (var j = 0; j < 16; j++) {
+ decToHex[i * 16 + j] = i.toString(16) + j.toString(16);
+ }
+ }
+
+ function createMatrixIdentity() {
+ return [
+ [1, 0, 0],
+ [0, 1, 0],
+ [0, 0, 1]
+ ];
+ }
+
+ function matrixMultiply(m1, m2) {
+ var result = createMatrixIdentity();
+
+ for (var x = 0; x < 3; x++) {
+ for (var y = 0; y < 3; y++) {
+ var sum = 0;
+
+ for (var z = 0; z < 3; z++) {
+ sum += m1[x][z] * m2[z][y];
+ }
+
+ result[x][y] = sum;
+ }
+ }
+ return result;
+ }
+
+ function copyState(o1, o2) {
+ o2.fillStyle = o1.fillStyle;
+ o2.lineCap = o1.lineCap;
+ o2.lineJoin = o1.lineJoin;
+ o2.lineWidth = o1.lineWidth;
+ o2.miterLimit = o1.miterLimit;
+ o2.shadowBlur = o1.shadowBlur;
+ o2.shadowColor = o1.shadowColor;
+ o2.shadowOffsetX = o1.shadowOffsetX;
+ o2.shadowOffsetY = o1.shadowOffsetY;
+ o2.strokeStyle = o1.strokeStyle;
+ o2.globalAlpha = o1.globalAlpha;
+ o2.font = o1.font;
+ o2.textAlign = o1.textAlign;
+ o2.textBaseline = o1.textBaseline;
+ o2.arcScaleX_ = o1.arcScaleX_;
+ o2.arcScaleY_ = o1.arcScaleY_;
+ o2.lineScale_ = o1.lineScale_;
+ }
+
+ var colorData = {
+ aliceblue: '#F0F8FF',
+ antiquewhite: '#FAEBD7',
+ aquamarine: '#7FFFD4',
+ azure: '#F0FFFF',
+ beige: '#F5F5DC',
+ bisque: '#FFE4C4',
+ black: '#000000',
+ blanchedalmond: '#FFEBCD',
+ blueviolet: '#8A2BE2',
+ brown: '#A52A2A',
+ burlywood: '#DEB887',
+ cadetblue: '#5F9EA0',
+ chartreuse: '#7FFF00',
+ chocolate: '#D2691E',
+ coral: '#FF7F50',
+ cornflowerblue: '#6495ED',
+ cornsilk: '#FFF8DC',
+ crimson: '#DC143C',
+ cyan: '#00FFFF',
+ darkblue: '#00008B',
+ darkcyan: '#008B8B',
+ darkgoldenrod: '#B8860B',
+ darkgray: '#A9A9A9',
+ darkgreen: '#006400',
+ darkgrey: '#A9A9A9',
+ darkkhaki: '#BDB76B',
+ darkmagenta: '#8B008B',
+ darkolivegreen: '#556B2F',
+ darkorange: '#FF8C00',
+ darkorchid: '#9932CC',
+ darkred: '#8B0000',
+ darksalmon: '#E9967A',
+ darkseagreen: '#8FBC8F',
+ darkslateblue: '#483D8B',
+ darkslategray: '#2F4F4F',
+ darkslategrey: '#2F4F4F',
+ darkturquoise: '#00CED1',
+ darkviolet: '#9400D3',
+ deeppink: '#FF1493',
+ deepskyblue: '#00BFFF',
+ dimgray: '#696969',
+ dimgrey: '#696969',
+ dodgerblue: '#1E90FF',
+ firebrick: '#B22222',
+ floralwhite: '#FFFAF0',
+ forestgreen: '#228B22',
+ gainsboro: '#DCDCDC',
+ ghostwhite: '#F8F8FF',
+ gold: '#FFD700',
+ goldenrod: '#DAA520',
+ grey: '#808080',
+ greenyellow: '#ADFF2F',
+ honeydew: '#F0FFF0',
+ hotpink: '#FF69B4',
+ indianred: '#CD5C5C',
+ indigo: '#4B0082',
+ ivory: '#FFFFF0',
+ khaki: '#F0E68C',
+ lavender: '#E6E6FA',
+ lavenderblush: '#FFF0F5',
+ lawngreen: '#7CFC00',
+ lemonchiffon: '#FFFACD',
+ lightblue: '#ADD8E6',
+ lightcoral: '#F08080',
+ lightcyan: '#E0FFFF',
+ lightgoldenrodyellow: '#FAFAD2',
+ lightgreen: '#90EE90',
+ lightgrey: '#D3D3D3',
+ lightpink: '#FFB6C1',
+ lightsalmon: '#FFA07A',
+ lightseagreen: '#20B2AA',
+ lightskyblue: '#87CEFA',
+ lightslategray: '#778899',
+ lightslategrey: '#778899',
+ lightsteelblue: '#B0C4DE',
+ lightyellow: '#FFFFE0',
+ limegreen: '#32CD32',
+ linen: '#FAF0E6',
+ magenta: '#FF00FF',
+ mediumaquamarine: '#66CDAA',
+ mediumblue: '#0000CD',
+ mediumorchid: '#BA55D3',
+ mediumpurple: '#9370DB',
+ mediumseagreen: '#3CB371',
+ mediumslateblue: '#7B68EE',
+ mediumspringgreen: '#00FA9A',
+ mediumturquoise: '#48D1CC',
+ mediumvioletred: '#C71585',
+ midnightblue: '#191970',
+ mintcream: '#F5FFFA',
+ mistyrose: '#FFE4E1',
+ moccasin: '#FFE4B5',
+ navajowhite: '#FFDEAD',
+ oldlace: '#FDF5E6',
+ olivedrab: '#6B8E23',
+ orange: '#FFA500',
+ orangered: '#FF4500',
+ orchid: '#DA70D6',
+ palegoldenrod: '#EEE8AA',
+ palegreen: '#98FB98',
+ paleturquoise: '#AFEEEE',
+ palevioletred: '#DB7093',
+ papayawhip: '#FFEFD5',
+ peachpuff: '#FFDAB9',
+ peru: '#CD853F',
+ pink: '#FFC0CB',
+ plum: '#DDA0DD',
+ powderblue: '#B0E0E6',
+ rosybrown: '#BC8F8F',
+ royalblue: '#4169E1',
+ saddlebrown: '#8B4513',
+ salmon: '#FA8072',
+ sandybrown: '#F4A460',
+ seagreen: '#2E8B57',
+ seashell: '#FFF5EE',
+ sienna: '#A0522D',
+ skyblue: '#87CEEB',
+ slateblue: '#6A5ACD',
+ slategray: '#708090',
+ slategrey: '#708090',
+ snow: '#FFFAFA',
+ springgreen: '#00FF7F',
+ steelblue: '#4682B4',
+ tan: '#D2B48C',
+ thistle: '#D8BFD8',
+ tomato: '#FF6347',
+ turquoise: '#40E0D0',
+ violet: '#EE82EE',
+ wheat: '#F5DEB3',
+ whitesmoke: '#F5F5F5',
+ yellowgreen: '#9ACD32'
+ };
+
+
+ function getRgbHslContent(styleString) {
+ var start = styleString.indexOf('(', 3);
+ var end = styleString.indexOf(')', start + 1);
+ var parts = styleString.substring(start + 1, end).split(',');
+ // add alpha if needed
+ if (parts.length != 4 || styleString.charAt(3) != 'a') {
+ parts[3] = 1;
+ }
+ return parts;
+ }
+
+ function percent(s) {
+ return parseFloat(s) / 100;
+ }
+
+ function clamp(v, min, max) {
+ return Math.min(max, Math.max(min, v));
+ }
+
+ function hslToRgb(parts){
+ var r, g, b, h, s, l;
+ h = parseFloat(parts[0]) / 360 % 360;
+ if (h < 0)
+ h++;
+ s = clamp(percent(parts[1]), 0, 1);
+ l = clamp(percent(parts[2]), 0, 1);
+ if (s == 0) {
+ r = g = b = l; // achromatic
+ } else {
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
+ var p = 2 * l - q;
+ r = hueToRgb(p, q, h + 1 / 3);
+ g = hueToRgb(p, q, h);
+ b = hueToRgb(p, q, h - 1 / 3);
+ }
+
+ return '#' + decToHex[Math.floor(r * 255)] +
+ decToHex[Math.floor(g * 255)] +
+ decToHex[Math.floor(b * 255)];
+ }
+
+ function hueToRgb(m1, m2, h) {
+ if (h < 0)
+ h++;
+ if (h > 1)
+ h--;
+
+ if (6 * h < 1)
+ return m1 + (m2 - m1) * 6 * h;
+ else if (2 * h < 1)
+ return m2;
+ else if (3 * h < 2)
+ return m1 + (m2 - m1) * (2 / 3 - h) * 6;
+ else
+ return m1;
+ }
+
+ var processStyleCache = {};
+
+ function processStyle(styleString) {
+ if (styleString in processStyleCache) {
+ return processStyleCache[styleString];
+ }
+
+ var str, alpha = 1;
+
+ styleString = String(styleString);
+ if (styleString.charAt(0) == '#') {
+ str = styleString;
+ } else if (/^rgb/.test(styleString)) {
+ var parts = getRgbHslContent(styleString);
+ var str = '#', n;
+ for (var i = 0; i < 3; i++) {
+ if (parts[i].indexOf('%') != -1) {
+ n = Math.floor(percent(parts[i]) * 255);
+ } else {
+ n = +parts[i];
+ }
+ str += decToHex[clamp(n, 0, 255)];
+ }
+ alpha = +parts[3];
+ } else if (/^hsl/.test(styleString)) {
+ var parts = getRgbHslContent(styleString);
+ str = hslToRgb(parts);
+ alpha = parts[3];
+ } else {
+ str = colorData[styleString] || styleString;
+ }
+ return processStyleCache[styleString] = {color: str, alpha: alpha};
+ }
+
+ var DEFAULT_STYLE = {
+ style: 'normal',
+ variant: 'normal',
+ weight: 'normal',
+ size: 10,
+ family: 'sans-serif'
+ };
+
+ // Internal text style cache
+ var fontStyleCache = {};
+
+ function processFontStyle(styleString) {
+ if (fontStyleCache[styleString]) {
+ return fontStyleCache[styleString];
+ }
+
+ var el = document.createElement('div');
+ var style = el.style;
+ try {
+ style.font = styleString;
+ } catch (ex) {
+ // Ignore failures to set to invalid font.
+ }
+
+ return fontStyleCache[styleString] = {
+ style: style.fontStyle || DEFAULT_STYLE.style,
+ variant: style.fontVariant || DEFAULT_STYLE.variant,
+ weight: style.fontWeight || DEFAULT_STYLE.weight,
+ size: style.fontSize || DEFAULT_STYLE.size,
+ family: style.fontFamily || DEFAULT_STYLE.family
+ };
+ }
+
+ function getComputedStyle(style, element) {
+ var computedStyle = {};
+
+ for (var p in style) {
+ computedStyle[p] = style[p];
+ }
+
+ // Compute the size
+ var canvasFontSize = parseFloat(element.currentStyle.fontSize),
+ fontSize = parseFloat(style.size);
+
+ if (typeof style.size == 'number') {
+ computedStyle.size = style.size;
+ } else if (style.size.indexOf('px') != -1) {
+ computedStyle.size = fontSize;
+ } else if (style.size.indexOf('em') != -1) {
+ computedStyle.size = canvasFontSize * fontSize;
+ } else if(style.size.indexOf('%') != -1) {
+ computedStyle.size = (canvasFontSize / 100) * fontSize;
+ } else if (style.size.indexOf('pt') != -1) {
+ computedStyle.size = fontSize / .75;
+ } else {
+ computedStyle.size = canvasFontSize;
+ }
+
+ // Different scaling between normal text and VML text. This was found using
+ // trial and error to get the same size as non VML text.
+ computedStyle.size *= 0.981;
+
+ return computedStyle;
+ }
+
+ function buildStyle(style) {
+ return style.style + ' ' + style.variant + ' ' + style.weight + ' ' +
+ style.size + 'px ' + style.family;
+ }
+
+ var lineCapMap = {
+ 'butt': 'flat',
+ 'round': 'round'
+ };
+
+ function processLineCap(lineCap) {
+ return lineCapMap[lineCap] || 'square';
+ }
+
+ /**
+ * This class implements CanvasRenderingContext2D interface as described by
+ * the WHATWG.
+ * @param {HTMLElement} canvasElement The element that the 2D context should
+ * be associated with
+ */
+ function CanvasRenderingContext2D_(canvasElement) {
+ this.m_ = createMatrixIdentity();
+
+ this.mStack_ = [];
+ this.aStack_ = [];
+ this.currentPath_ = [];
+
+ // Canvas context properties
+ this.strokeStyle = '#000';
+ this.fillStyle = '#000';
+
+ this.lineWidth = 1;
+ this.lineJoin = 'miter';
+ this.lineCap = 'butt';
+ this.miterLimit = Z * 1;
+ this.globalAlpha = 1;
+ this.font = '10px sans-serif';
+ this.textAlign = 'left';
+ this.textBaseline = 'alphabetic';
+ this.canvas = canvasElement;
+
+ var cssText = 'width:' + canvasElement.clientWidth + 'px;height:' +
+ canvasElement.clientHeight + 'px;overflow:hidden;position:absolute';
+ var el = canvasElement.ownerDocument.createElement('div');
+ el.style.cssText = cssText;
+ canvasElement.appendChild(el);
+
+ var overlayEl = el.cloneNode(false);
+ // Use a non transparent background.
+ overlayEl.style.backgroundColor = 'red';
+ overlayEl.style.filter = 'alpha(opacity=0)';
+ canvasElement.appendChild(overlayEl);
+
+ this.element_ = el;
+ this.arcScaleX_ = 1;
+ this.arcScaleY_ = 1;
+ this.lineScale_ = 1;
+ }
+
+ var contextPrototype = CanvasRenderingContext2D_.prototype;
+ contextPrototype.clearRect = function() {
+ if (this.textMeasureEl_) {
+ this.textMeasureEl_.removeNode(true);
+ this.textMeasureEl_ = null;
+ }
+ this.element_.innerHTML = '';
+ };
+
+ contextPrototype.beginPath = function() {
+ // TODO: Branch current matrix so that save/restore has no effect
+ // as per safari docs.
+ this.currentPath_ = [];
+ };
+
+ contextPrototype.moveTo = function(aX, aY) {
+ var p = getCoords(this, aX, aY);
+ this.currentPath_.push({type: 'moveTo', x: p.x, y: p.y});
+ this.currentX_ = p.x;
+ this.currentY_ = p.y;
+ };
+
+ contextPrototype.lineTo = function(aX, aY) {
+ var p = getCoords(this, aX, aY);
+ this.currentPath_.push({type: 'lineTo', x: p.x, y: p.y});
+
+ this.currentX_ = p.x;
+ this.currentY_ = p.y;
+ };
+
+ contextPrototype.bezierCurveTo = function(aCP1x, aCP1y,
+ aCP2x, aCP2y,
+ aX, aY) {
+ var p = getCoords(this, aX, aY);
+ var cp1 = getCoords(this, aCP1x, aCP1y);
+ var cp2 = getCoords(this, aCP2x, aCP2y);
+ bezierCurveTo(this, cp1, cp2, p);
+ };
+
+ // Helper function that takes the already fixed cordinates.
+ function bezierCurveTo(self, cp1, cp2, p) {
+ self.currentPath_.push({
+ type: 'bezierCurveTo',
+ cp1x: cp1.x,
+ cp1y: cp1.y,
+ cp2x: cp2.x,
+ cp2y: cp2.y,
+ x: p.x,
+ y: p.y
+ });
+ self.currentX_ = p.x;
+ self.currentY_ = p.y;
+ }
+
+ contextPrototype.quadraticCurveTo = function(aCPx, aCPy, aX, aY) {
+ // the following is lifted almost directly from
+ // http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes
+
+ var cp = getCoords(this, aCPx, aCPy);
+ var p = getCoords(this, aX, aY);
+
+ var cp1 = {
+ x: this.currentX_ + 2.0 / 3.0 * (cp.x - this.currentX_),
+ y: this.currentY_ + 2.0 / 3.0 * (cp.y - this.currentY_)
+ };
+ var cp2 = {
+ x: cp1.x + (p.x - this.currentX_) / 3.0,
+ y: cp1.y + (p.y - this.currentY_) / 3.0
+ };
+
+ bezierCurveTo(this, cp1, cp2, p);
+ };
+
+ contextPrototype.arc = function(aX, aY, aRadius,
+ aStartAngle, aEndAngle, aClockwise) {
+ aRadius *= Z;
+ var arcType = aClockwise ? 'at' : 'wa';
+
+ var xStart = aX + mc(aStartAngle) * aRadius - Z2;
+ var yStart = aY + ms(aStartAngle) * aRadius - Z2;
+
+ var xEnd = aX + mc(aEndAngle) * aRadius - Z2;
+ var yEnd = aY + ms(aEndAngle) * aRadius - Z2;
+
+ // IE won't render arches drawn counter clockwise if xStart == xEnd.
+ if (xStart == xEnd && !aClockwise) {
+ xStart += 0.125; // Offset xStart by 1/80 of a pixel. Use something
+ // that can be represented in binary
+ }
+
+ var p = getCoords(this, aX, aY);
+ var pStart = getCoords(this, xStart, yStart);
+ var pEnd = getCoords(this, xEnd, yEnd);
+
+ this.currentPath_.push({type: arcType,
+ x: p.x,
+ y: p.y,
+ radius: aRadius,
+ xStart: pStart.x,
+ yStart: pStart.y,
+ xEnd: pEnd.x,
+ yEnd: pEnd.y});
+
+ };
+
+ contextPrototype.rect = function(aX, aY, aWidth, aHeight) {
+ this.moveTo(aX, aY);
+ this.lineTo(aX + aWidth, aY);
+ this.lineTo(aX + aWidth, aY + aHeight);
+ this.lineTo(aX, aY + aHeight);
+ this.closePath();
+ };
+
+ contextPrototype.strokeRect = function(aX, aY, aWidth, aHeight) {
+ var oldPath = this.currentPath_;
+ this.beginPath();
+
+ this.moveTo(aX, aY);
+ this.lineTo(aX + aWidth, aY);
+ this.lineTo(aX + aWidth, aY + aHeight);
+ this.lineTo(aX, aY + aHeight);
+ this.closePath();
+ this.stroke();
+
+ this.currentPath_ = oldPath;
+ };
+
+ contextPrototype.fillRect = function(aX, aY, aWidth, aHeight) {
+ var oldPath = this.currentPath_;
+ this.beginPath();
+
+ this.moveTo(aX, aY);
+ this.lineTo(aX + aWidth, aY);
+ this.lineTo(aX + aWidth, aY + aHeight);
+ this.lineTo(aX, aY + aHeight);
+ this.closePath();
+ this.fill();
+
+ this.currentPath_ = oldPath;
+ };
+
+ contextPrototype.createLinearGradient = function(aX0, aY0, aX1, aY1) {
+ var gradient = new CanvasGradient_('gradient');
+ gradient.x0_ = aX0;
+ gradient.y0_ = aY0;
+ gradient.x1_ = aX1;
+ gradient.y1_ = aY1;
+ return gradient;
+ };
+
+ contextPrototype.createRadialGradient = function(aX0, aY0, aR0,
+ aX1, aY1, aR1) {
+ var gradient = new CanvasGradient_('gradientradial');
+ gradient.x0_ = aX0;
+ gradient.y0_ = aY0;
+ gradient.r0_ = aR0;
+ gradient.x1_ = aX1;
+ gradient.y1_ = aY1;
+ gradient.r1_ = aR1;
+ return gradient;
+ };
+
+ contextPrototype.drawImage = function(image, var_args) {
+ var dx, dy, dw, dh, sx, sy, sw, sh;
+
+ // to find the original width we overide the width and height
+ var oldRuntimeWidth = image.runtimeStyle.width;
+ var oldRuntimeHeight = image.runtimeStyle.height;
+ image.runtimeStyle.width = 'auto';
+ image.runtimeStyle.height = 'auto';
+
+ // get the original size
+ var w = image.width;
+ var h = image.height;
+
+ // and remove overides
+ image.runtimeStyle.width = oldRuntimeWidth;
+ image.runtimeStyle.height = oldRuntimeHeight;
+
+ if (arguments.length == 3) {
+ dx = arguments[1];
+ dy = arguments[2];
+ sx = sy = 0;
+ sw = dw = w;
+ sh = dh = h;
+ } else if (arguments.length == 5) {
+ dx = arguments[1];
+ dy = arguments[2];
+ dw = arguments[3];
+ dh = arguments[4];
+ sx = sy = 0;
+ sw = w;
+ sh = h;
+ } else if (arguments.length == 9) {
+ sx = arguments[1];
+ sy = arguments[2];
+ sw = arguments[3];
+ sh = arguments[4];
+ dx = arguments[5];
+ dy = arguments[6];
+ dw = arguments[7];
+ dh = arguments[8];
+ } else {
+ throw Error('Invalid number of arguments');
+ }
+
+ var d = getCoords(this, dx, dy);
+
+ var w2 = sw / 2;
+ var h2 = sh / 2;
+
+ var vmlStr = [];
+
+ var W = 10;
+ var H = 10;
+
+ // For some reason that I've now forgotten, using divs didn't work
+ vmlStr.push(' <g_vml_:group',
+ ' coordsize="', Z * W, ',', Z * H, '"',
+ ' coordorigin="0,0"' ,
+ ' style="width:', W, 'px;height:', H, 'px;position:absolute;');
+
+ // If filters are necessary (rotation exists), create them
+ // filters are bog-slow, so only create them if abbsolutely necessary
+ // The following check doesn't account for skews (which don't exist
+ // in the canvas spec (yet) anyway.
+
+ if (this.m_[0][0] != 1 || this.m_[0][1] ||
+ this.m_[1][1] != 1 || this.m_[1][0]) {
+ var filter = [];
+
+ // Note the 12/21 reversal
+ filter.push('M11=', this.m_[0][0], ',',
+ 'M12=', this.m_[1][0], ',',
+ 'M21=', this.m_[0][1], ',',
+ 'M22=', this.m_[1][1], ',',
+ 'Dx=', mr(d.x / Z), ',',
+ 'Dy=', mr(d.y / Z), '');
+
+ // Bounding box calculation (need to minimize displayed area so that
+ // filters don't waste time on unused pixels.
+ var max = d;
+ var c2 = getCoords(this, dx + dw, dy);
+ var c3 = getCoords(this, dx, dy + dh);
+ var c4 = getCoords(this, dx + dw, dy + dh);
+
+ max.x = m.max(max.x, c2.x, c3.x, c4.x);
+ max.y = m.max(max.y, c2.y, c3.y, c4.y);
+
+ vmlStr.push('padding:0 ', mr(max.x / Z), 'px ', mr(max.y / Z),
+ 'px 0;filter:progid:DXImageTransform.Microsoft.Matrix(',
+ filter.join(''), ", sizingmethod='clip');");
+
+ } else {
+ vmlStr.push('top:', mr(d.y / Z), 'px;left:', mr(d.x / Z), 'px;');
+ }
+
+ vmlStr.push(' ">' ,
+ '<g_vml_:image src="', image.src, '"',
+ ' style="width:', Z * dw, 'px;',
+ ' height:', Z * dh, 'px"',
+ ' cropleft="', sx / w, '"',
+ ' croptop="', sy / h, '"',
+ ' cropright="', (w - sx - sw) / w, '"',
+ ' cropbottom="', (h - sy - sh) / h, '"',
+ ' />',
+ '</g_vml_:group>');
+
+ this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join(''));
+ };
+
+ contextPrototype.stroke = function(aFill) {
+ var lineStr = [];
+ var lineOpen = false;
+
+ var W = 10;
+ var H = 10;
+
+ lineStr.push('<g_vml_:shape',
+ ' filled="', !!aFill, '"',
+ ' style="position:absolute;width:', W, 'px;height:', H, 'px;"',
+ ' coordorigin="0,0"',
+ ' coordsize="', Z * W, ',', Z * H, '"',
+ ' stroked="', !aFill, '"',
+ ' path="');
+
+ var newSeq = false;
+ var min = {x: null, y: null};
+ var max = {x: null, y: null};
+
+ for (var i = 0; i < this.currentPath_.length; i++) {
+ var p = this.currentPath_[i];
+ var c;
+
+ switch (p.type) {
+ case 'moveTo':
+ c = p;
+ lineStr.push(' m ', mr(p.x), ',', mr(p.y));
+ break;
+ case 'lineTo':
+ lineStr.push(' l ', mr(p.x), ',', mr(p.y));
+ break;
+ case 'close':
+ lineStr.push(' x ');
+ p = null;
+ break;
+ case 'bezierCurveTo':
+ lineStr.push(' c ',
+ mr(p.cp1x), ',', mr(p.cp1y), ',',
+ mr(p.cp2x), ',', mr(p.cp2y), ',',
+ mr(p.x), ',', mr(p.y));
+ break;
+ case 'at':
+ case 'wa':
+ lineStr.push(' ', p.type, ' ',
+ mr(p.x - this.arcScaleX_ * p.radius), ',',
+ mr(p.y - this.arcScaleY_ * p.radius), ' ',
+ mr(p.x + this.arcScaleX_ * p.radius), ',',
+ mr(p.y + this.arcScaleY_ * p.radius), ' ',
+ mr(p.xStart), ',', mr(p.yStart), ' ',
+ mr(p.xEnd), ',', mr(p.yEnd));
+ break;
+ }
+
+
+ // TODO: Following is broken for curves due to
+ // move to proper paths.
+
+ // Figure out dimensions so we can do gradient fills
+ // properly
+ if (p) {
+ if (min.x == null || p.x < min.x) {
+ min.x = p.x;
+ }
+ if (max.x == null || p.x > max.x) {
+ max.x = p.x;
+ }
+ if (min.y == null || p.y < min.y) {
+ min.y = p.y;
+ }
+ if (max.y == null || p.y > max.y) {
+ max.y = p.y;
+ }
+ }
+ }
+ lineStr.push(' ">');
+
+ if (!aFill) {
+ appendStroke(this, lineStr);
+ } else {
+ appendFill(this, lineStr, min, max);
+ }
+
+ lineStr.push('</g_vml_:shape>');
+
+ this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));
+ };
+
+ function appendStroke(ctx, lineStr) {
+ var a = processStyle(ctx.strokeStyle);
+ var color = a.color;
+ var opacity = a.alpha * ctx.globalAlpha;
+ var lineWidth = ctx.lineScale_ * ctx.lineWidth;
+
+ // VML cannot correctly render a line if the width is less than 1px.
+ // In that case, we dilute the color to make the line look thinner.
+ if (lineWidth < 1) {
+ opacity *= lineWidth;
+ }
+
+ lineStr.push(
+ '<g_vml_:stroke',
+ ' opacity="', opacity, '"',
+ ' joinstyle="', ctx.lineJoin, '"',
+ ' miterlimit="', ctx.miterLimit, '"',
+ ' endcap="', processLineCap(ctx.lineCap), '"',
+ ' weight="', lineWidth, 'px"',
+ ' color="', color, '" />'
+ );
+ }
+
+ function appendFill(ctx, lineStr, min, max) {
+ var fillStyle = ctx.fillStyle;
+ var arcScaleX = ctx.arcScaleX_;
+ var arcScaleY = ctx.arcScaleY_;
+ var width = max.x - min.x;
+ var height = max.y - min.y;
+ if (fillStyle instanceof CanvasGradient_) {
+ // TODO: Gradients transformed with the transformation matrix.
+ var angle = 0;
+ var focus = {x: 0, y: 0};
+
+ // additional offset
+ var shift = 0;
+ // scale factor for offset
+ var expansion = 1;
+
+ if (fillStyle.type_ == 'gradient') {
+ var x0 = fillStyle.x0_ / arcScaleX;
+ var y0 = fillStyle.y0_ / arcScaleY;
+ var x1 = fillStyle.x1_ / arcScaleX;
+ var y1 = fillStyle.y1_ / arcScaleY;
+ var p0 = getCoords(ctx, x0, y0);
+ var p1 = getCoords(ctx, x1, y1);
+ var dx = p1.x - p0.x;
+ var dy = p1.y - p0.y;
+ angle = Math.atan2(dx, dy) * 180 / Math.PI;
+
+ // The angle should be a non-negative number.
+ if (angle < 0) {
+ angle += 360;
+ }
+
+ // Very small angles produce an unexpected result because they are
+ // converted to a scientific notation string.
+ if (angle < 1e-6) {
+ angle = 0;
+ }
+ } else {
+ var p0 = getCoords(ctx, fillStyle.x0_, fillStyle.y0_);
+ focus = {
+ x: (p0.x - min.x) / width,
+ y: (p0.y - min.y) / height
+ };
+
+ width /= arcScaleX * Z;
+ height /= arcScaleY * Z;
+ var dimension = m.max(width, height);
+ shift = 2 * fillStyle.r0_ / dimension;
+ expansion = 2 * fillStyle.r1_ / dimension - shift;
+ }
+
+ // We need to sort the color stops in ascending order by offset,
+ // otherwise IE won't interpret it correctly.
+ var stops = fillStyle.colors_;
+ stops.sort(function(cs1, cs2) {
+ return cs1.offset - cs2.offset;
+ });
+
+ var length = stops.length;
+ var color1 = stops[0].color;
+ var color2 = stops[length - 1].color;
+ var opacity1 = stops[0].alpha * ctx.globalAlpha;
+ var opacity2 = stops[length - 1].alpha * ctx.globalAlpha;
+
+ var colors = [];
+ for (var i = 0; i < length; i++) {
+ var stop = stops[i];
+ colors.push(stop.offset * expansion + shift + ' ' + stop.color);
+ }
+
+ // When colors attribute is used, the meanings of opacity and o:opacity2
+ // are reversed.
+ lineStr.push('<g_vml_:fill type="', fillStyle.type_, '"',
+ ' method="none" focus="100%"',
+ ' color="', color1, '"',
+ ' color2="', color2, '"',
+ ' colors="', colors.join(','), '"',
+ ' opacity="', opacity2, '"',
+ ' g_o_:opacity2="', opacity1, '"',
+ ' angle="', angle, '"',
+ ' focusposition="', focus.x, ',', focus.y, '" />');
+ } else if (fillStyle instanceof CanvasPattern_) {
+ if (width && height) {
+ var deltaLeft = -min.x;
+ var deltaTop = -min.y;
+ lineStr.push('<g_vml_:fill',
+ ' position="',
+ deltaLeft / width * arcScaleX * arcScaleX, ',',
+ deltaTop / height * arcScaleY * arcScaleY, '"',
+ ' type="tile"',
+ // TODO: Figure out the correct size to fit the scale.
+ //' size="', w, 'px ', h, 'px"',
+ ' src="', fillStyle.src_, '" />');
+ }
+ } else {
+ var a = processStyle(ctx.fillStyle);
+ var color = a.color;
+ var opacity = a.alpha * ctx.globalAlpha;
+ lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity,
+ '" />');
+ }
+ }
+
+ contextPrototype.fill = function() {
+ this.stroke(true);
+ };
+
+ contextPrototype.closePath = function() {
+ this.currentPath_.push({type: 'close'});
+ };
+
+ function getCoords(ctx, aX, aY) {
+ var m = ctx.m_;
+ return {
+ x: Z * (aX * m[0][0] + aY * m[1][0] + m[2][0]) - Z2,
+ y: Z * (aX * m[0][1] + aY * m[1][1] + m[2][1]) - Z2
+ };
+ };
+
+ contextPrototype.save = function() {
+ var o = {};
+ copyState(this, o);
+ this.aStack_.push(o);
+ this.mStack_.push(this.m_);
+ this.m_ = matrixMultiply(createMatrixIdentity(), this.m_);
+ };
+
+ contextPrototype.restore = function() {
+ if (this.aStack_.length) {
+ copyState(this.aStack_.pop(), this);
+ this.m_ = this.mStack_.pop();
+ }
+ };
+
+ function matrixIsFinite(m) {
+ return isFinite(m[0][0]) && isFinite(m[0][1]) &&
+ isFinite(m[1][0]) && isFinite(m[1][1]) &&
+ isFinite(m[2][0]) && isFinite(m[2][1]);
+ }
+
+ function setM(ctx, m, updateLineScale) {
+ if (!matrixIsFinite(m)) {
+ return;
+ }
+ ctx.m_ = m;
+
+ if (updateLineScale) {
+ // Get the line scale.
+ // Determinant of this.m_ means how much the area is enlarged by the
+ // transformation. So its square root can be used as a scale factor
+ // for width.
+ var det = m[0][0] * m[1][1] - m[0][1] * m[1][0];
+ ctx.lineScale_ = sqrt(abs(det));
+ }
+ }
+
+ contextPrototype.translate = function(aX, aY) {
+ var m1 = [
+ [1, 0, 0],
+ [0, 1, 0],
+ [aX, aY, 1]
+ ];
+
+ setM(this, matrixMultiply(m1, this.m_), false);
+ };
+
+ contextPrototype.rotate = function(aRot) {
+ var c = mc(aRot);
+ var s = ms(aRot);
+
+ var m1 = [
+ [c, s, 0],
+ [-s, c, 0],
+ [0, 0, 1]
+ ];
+
+ setM(this, matrixMultiply(m1, this.m_), false);
+ };
+
+ contextPrototype.scale = function(aX, aY) {
+ this.arcScaleX_ *= aX;
+ this.arcScaleY_ *= aY;
+ var m1 = [
+ [aX, 0, 0],
+ [0, aY, 0],
+ [0, 0, 1]
+ ];
+
+ setM(this, matrixMultiply(m1, this.m_), true);
+ };
+
+ contextPrototype.transform = function(m11, m12, m21, m22, dx, dy) {
+ var m1 = [
+ [m11, m12, 0],
+ [m21, m22, 0],
+ [dx, dy, 1]
+ ];
+
+ setM(this, matrixMultiply(m1, this.m_), true);
+ };
+
+ contextPrototype.setTransform = function(m11, m12, m21, m22, dx, dy) {
+ var m = [
+ [m11, m12, 0],
+ [m21, m22, 0],
+ [dx, dy, 1]
+ ];
+
+ setM(this, m, true);
+ };
+
+ /**
+ * The text drawing function.
+ * The maxWidth argument isn't taken in account, since no browser supports
+ * it yet.
+ */
+ contextPrototype.drawText_ = function(text, x, y, maxWidth, stroke) {
+ var m = this.m_,
+ delta = 1000,
+ left = 0,
+ right = delta,
+ offset = {x: 0, y: 0},
+ lineStr = [];
+
+ var fontStyle = getComputedStyle(processFontStyle(this.font),
+ this.element_);
+
+ var fontStyleString = buildStyle(fontStyle);
+
+ var elementStyle = this.element_.currentStyle;
+ var textAlign = this.textAlign.toLowerCase();
+ switch (textAlign) {
+ case 'left':
+ case 'center':
+ case 'right':
+ break;
+ case 'end':
+ textAlign = elementStyle.direction == 'ltr' ? 'right' : 'left';
+ break;
+ case 'start':
+ textAlign = elementStyle.direction == 'rtl' ? 'right' : 'left';
+ break;
+ default:
+ textAlign = 'left';
+ }
+
+ // 1.75 is an arbitrary number, as there is no info about the text baseline
+ switch (this.textBaseline) {
+ case 'hanging':
+ case 'top':
+ offset.y = fontStyle.size / 1.75;
+ break;
+ case 'middle':
+ break;
+ default:
+ case null:
+ case 'alphabetic':
+ case 'ideographic':
+ case 'bottom':
+ offset.y = -fontStyle.size / 2.25;
+ break;
+ }
+
+ switch(textAlign) {
+ case 'right':
+ left = delta;
+ right = 0.05;
+ break;
+ case 'center':
+ left = right = delta / 2;
+ break;
+ }
+
+ var d = getCoords(this, x + offset.x, y + offset.y);
+
+ lineStr.push('<g_vml_:line from="', -left ,' 0" to="', right ,' 0.05" ',
+ ' coordsize="100 100" coordorigin="0 0"',
+ ' filled="', !stroke, '" stroked="', !!stroke,
+ '" style="position:absolute;width:1px;height:1px;">');
+
+ if (stroke) {
+ appendStroke(this, lineStr);
+ } else {
+ // TODO: Fix the min and max params.
+ appendFill(this, lineStr, {x: -left, y: 0},
+ {x: right, y: fontStyle.size});
+ }
+
+ var skewM = m[0][0].toFixed(3) + ',' + m[1][0].toFixed(3) + ',' +
+ m[0][1].toFixed(3) + ',' + m[1][1].toFixed(3) + ',0,0';
+
+ var skewOffset = mr(d.x / Z) + ',' + mr(d.y / Z);
+
+ lineStr.push('<g_vml_:skew on="t" matrix="', skewM ,'" ',
+ ' offset="', skewOffset, '" origin="', left ,' 0" />',
+ '<g_vml_:path textpathok="true" />',
+ '<g_vml_:textpath on="true" string="',
+ encodeHtmlAttribute(text),
+ '" style="v-text-align:', textAlign,
+ ';font:', encodeHtmlAttribute(fontStyleString),
+ '" /></g_vml_:line>');
+
+ this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));
+ };
+
+ contextPrototype.fillText = function(text, x, y, maxWidth) {
+ this.drawText_(text, x, y, maxWidth, false);
+ };
+
+ contextPrototype.strokeText = function(text, x, y, maxWidth) {
+ this.drawText_(text, x, y, maxWidth, true);
+ };
+
+ contextPrototype.measureText = function(text) {
+ if (!this.textMeasureEl_) {
+ var s = '<span style="position:absolute;' +
+ 'top:-20000px;left:0;padding:0;margin:0;border:none;' +
+ 'white-space:pre;"></span>';
+ this.element_.insertAdjacentHTML('beforeEnd', s);
+ this.textMeasureEl_ = this.element_.lastChild;
+ }
+ var doc = this.element_.ownerDocument;
+ this.textMeasureEl_.innerHTML = '';
+ this.textMeasureEl_.style.font = this.font;
+ // Don't use innerHTML or innerText because they allow markup/whitespace.
+ this.textMeasureEl_.appendChild(doc.createTextNode(text));
+ return {width: this.textMeasureEl_.offsetWidth};
+ };
+
+ /******** STUBS ********/
+ contextPrototype.clip = function() {
+ // TODO: Implement
+ };
+
+ contextPrototype.arcTo = function() {
+ // TODO: Implement
+ };
+
+ contextPrototype.createPattern = function(image, repetition) {
+ return new CanvasPattern_(image, repetition);
+ };
+
+ // Gradient / Pattern Stubs
+ function CanvasGradient_(aType) {
+ this.type_ = aType;
+ this.x0_ = 0;
+ this.y0_ = 0;
+ this.r0_ = 0;
+ this.x1_ = 0;
+ this.y1_ = 0;
+ this.r1_ = 0;
+ this.colors_ = [];
+ }
+
+ CanvasGradient_.prototype.addColorStop = function(aOffset, aColor) {
+ aColor = processStyle(aColor);
+ this.colors_.push({offset: aOffset,
+ color: aColor.color,
+ alpha: aColor.alpha});
+ };
+
+ function CanvasPattern_(image, repetition) {
+ assertImageIsValid(image);
+ switch (repetition) {
+ case 'repeat':
+ case null:
+ case '':
+ this.repetition_ = 'repeat';
+ break
+ case 'repeat-x':
+ case 'repeat-y':
+ case 'no-repeat':
+ this.repetition_ = repetition;
+ break;
+ default:
+ throwException('SYNTAX_ERR');
+ }
+
+ this.src_ = image.src;
+ this.width_ = image.width;
+ this.height_ = image.height;
+ }
+
+ function throwException(s) {
+ throw new DOMException_(s);
+ }
+
+ function assertImageIsValid(img) {
+ if (!img || img.nodeType != 1 || img.tagName != 'IMG') {
+ throwException('TYPE_MISMATCH_ERR');
+ }
+ if (img.readyState != 'complete') {
+ throwException('INVALID_STATE_ERR');
+ }
+ }
+
+ function DOMException_(s) {
+ this.code = this[s];
+ this.message = s +': DOM Exception ' + this.code;
+ }
+ var p = DOMException_.prototype = new Error;
+ p.INDEX_SIZE_ERR = 1;
+ p.DOMSTRING_SIZE_ERR = 2;
+ p.HIERARCHY_REQUEST_ERR = 3;
+ p.WRONG_DOCUMENT_ERR = 4;
+ p.INVALID_CHARACTER_ERR = 5;
+ p.NO_DATA_ALLOWED_ERR = 6;
+ p.NO_MODIFICATION_ALLOWED_ERR = 7;
+ p.NOT_FOUND_ERR = 8;
+ p.NOT_SUPPORTED_ERR = 9;
+ p.INUSE_ATTRIBUTE_ERR = 10;
+ p.INVALID_STATE_ERR = 11;
+ p.SYNTAX_ERR = 12;
+ p.INVALID_MODIFICATION_ERR = 13;
+ p.NAMESPACE_ERR = 14;
+ p.INVALID_ACCESS_ERR = 15;
+ p.VALIDATION_ERR = 16;
+ p.TYPE_MISMATCH_ERR = 17;
+
+ // set up externs
+ G_vmlCanvasManager = G_vmlCanvasManager_;
+ CanvasRenderingContext2D = CanvasRenderingContext2D_;
+ CanvasGradient = CanvasGradient_;
+ CanvasPattern = CanvasPattern_;
+ DOMException = DOMException_;
+})();
+
+} // if
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/qmf-ui.js b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/qmf-ui.js
new file mode 100644
index 0000000000..e7fb92835d
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qmf-ui/scripts/qmf-ui.js
@@ -0,0 +1,3526 @@
+/**
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This program implements the QMF Console User Interface logic for qmf.html
+ *
+ * It has dependencies on the following:
+ * qmf.css
+ * itablet.css
+ * iscroll.js
+ * jquery.js (jquery-1.7.1.min.js)
+ * itablet.js
+ * excanvas.js (for IE < 9 only)
+ * qpid.js
+ *
+ * author Fraser Adams
+ */
+
+//-------------------------------------------------------------------------------------------------------------------
+
+// Create a new namespace for the qmfui "package".
+var qmfui = {};
+qmfui.TOUCH_ENABLED = 'ontouchstart' in window && !((/hp-tablet/gi).test(navigator.appVersion));
+qmfui.END_EV = (qmfui.TOUCH_ENABLED) ? "touchend" : "mouseup";
+
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * This class holds the history of various key statistics that may be held for some QMF
+ * Management Objects so we may see how the state has changes over a particular time range.
+ */
+qmfui.Statistics = function(description) {
+ this.description = description; // Array describing the contents of each stored statistic
+ this.short = new util.RingBuffer(60); // Statistics for a 10 minute period (10*60/REFRESH_PERIOD)
+ this.medium = new util.RingBuffer(60); // Statistics for a 1 hour period (Entries are updated every minute)
+ this.long = new util.RingBuffer(144); // Statistics for a 1 day period (Entries are updated every 10 minutes)
+
+ /**
+ * Add an item to the end of each statistic buffer.
+ * @param item an array containing the current statistics for each property that we want to hold for a
+ * Management Object, the last item in the array is the Management Object's update timestamp.
+ * As an example for the connection Management Object we would do:
+ * stats.put([connection.msgsFromClient, connection.msgsToClient, connection._update_ts]);
+ * This approach is a little ugly and not terribly OO, but it's pretty memory efficient, which is
+ * important as there could be lots of Management Objects on a heavily utilised broker.
+ */
+ this.put = function(item) {
+ var TIMESTAMP = item.length - 1; // The timestamp is stored as the last item of each sample.
+ var timestamp = item[TIMESTAMP];
+
+ var lastItem = this.short.getLast();
+ if (lastItem == null) {
+ this.short.put(item); // Update the 10 minute period statistics.
+ } else {
+ var lastTimestamp = lastItem[TIMESTAMP];
+ // 9000000000 is 9 seconds in nanoseconds. If the time delta is less than 9 seconds we hold off adding
+ // the sample otherwise the ring buffer will end up holding less than the full 10 minutes worth.
+ if ((timestamp - lastTimestamp) >= 9000000000) {
+ this.short.put(item); // Update the 10 minute period statistics.
+ }
+ }
+
+ var lastItem = this.medium.getLast();
+ if (lastItem == null) {
+ this.medium.put(item); // Update the 1 hour period statistics.
+ } else {
+ var lastTimestamp = lastItem[TIMESTAMP];
+ // 59000000000 is 59 seconds in nanoseconds. We use 59 seconds rather than 60 seconds because the
+ // update period has a modest +/i variance around 10 seconds.
+ if ((timestamp - lastTimestamp) >= 59000000000) {
+ this.medium.put(item); // Update the 1 hour period statistics.
+ }
+ }
+
+ lastItem = this.long.getLast();
+ if (lastItem == null) {
+ this.long.put(item); // Update the 1 day period statistics.
+ } else {
+ var lastTimestamp = lastItem[TIMESTAMP];
+ // 599000000000 is 599 seconds in nanoseconds (just short of 10 minutes). We use 599 seconds rather
+ // than 600 seconds because the update period has a modest +/ variance around 10 seconds.
+ if ((timestamp - lastTimestamp) >= 599000000000) {
+ this.long.put(item); // Update the 1 day period statistics.
+ }
+ }
+ };
+
+ /**
+ * This method computes the most recent instantaneous rate for the property specified by the index.
+ * For example for the Connection Management Object an index of 1 would represent msgsToClient as
+ * described in the comments for put(). Note that the rate that is returned is the most recent
+ * instantaneous rate, which means that it uses the samples held in the ring buffer used to hold
+ * the ten minute window.
+ * @param the index of the property that we wish to obtain the rate for.
+ * @return the most recent intantaneous rate in items/s
+ */
+ this.getRate = function(index) {
+ var size = this.short.size();
+ if (size < 2) {
+ return 0;
+ }
+
+ var s1 = this.short.get(size - 2);
+ var t1 = s1[s1.length - 1];
+
+ var s2 = this.short.get(size - 1);
+ var t2 = s2[s2.length - 1];
+
+ var delta = (t2 == t1) ? 0.0000001 : t2 - t1; // Shouldn't happen, but this tries to avoid divide by zero.
+ var rate = ((s2[index] - s1[index]) * 1000000000)/delta
+ return rate;
+ };
+};
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Main Console Class
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the main Console class.
+ * This class contains the QMF Console and and caches the core QMF management objects. Caching the getObjects()
+ * results is obviously sensible and helps avoid the temptation to call getObjects() elsewhere which is rather
+ * inefficient as it is invoked using AMQP request/response but morever in the case of this UI is is called via
+ * a REST proxy. Caching getObjects() calls also helps to abstract the asynchronous nature of JavaScript as the
+ * cache methods can be called synchronously which "feels" a more natural way to get the data.
+ *
+ * This class is also responsible for initialising the rest of the pages when jQuery.ready() fires and updating
+ * them when QMF object updates occur, in other words it might be considered "Main".
+ *
+ * This class handles the QMF Console Connection lifecycle management. It's worth pointing out that it's fairly
+ * subtle and complex particularly due to the asynchronous nature of JavaScript. It's made even more complex
+ * by the fact that there are two distinct ways used to decide when to get the QMF Management Objects. The default
+ * way is where QMF Event delivery is enabled, in this case the onEvent() method is triggered periodically by
+ * the underlying QMF Console's Event dispatcher and in this case the Event dispatcher takes care of reconnection
+ * attempts. However if disableEvents is selected then the QMF Management Objects are retrieved via a timed
+ * poll. In this case this method must correctly start the pollForData() but must also let it expire if the user
+ * selects a new Connection that has QMF Event deliver enabled.
+ */
+qmfui.Console = new function() {
+ /**
+ * This is an array of QMF Console Connections that the user is interested in. It gets initiated with the
+ * default connection (that is to say the connection that the REST API has been configured to use if no
+ * explicit URL has been supplied). Using a Connection URL of "" makes the REST API use its default.
+ * This property has been exposed as a "public" property of qmfui.Console because then it becomes possible
+ * to "configure" the initial set of consoleConnections via a trivial config.js file containing:
+ * qmfui.Console.consoleConnections = [{name: "default", url: ""},{name: "wildcard", url: "0.0.0.0:5672",
+ * connectionOptions: {sasl_mechs:"ANONYMOUS"}, disableEvents: true}];
+ * i.e. a JSON array of Console Connection settings.
+ */
+ this.consoleConnections = [{name: "default", url: ""}];
+
+ var _objects = {}; // A map used to cache the QMF Management Object lists returned by getObjects().
+ var _disableEvents = false; // Set for Connections that have Events disabled and thus refresh via timed polling.
+ var _polling = false; // Set when the timed polling is active so we can avoid starting it multiple times.
+ var _receivedData = false; // This flag is used to tell the difference between a failure to connect and a disconnect.
+ var _console = null; // The QMF Console used to retrieve information from the broker.
+ var _connection = null;
+ var _activeConsoleConnection = 0; // The index of the currently active QMF Console Connection.
+
+ /**
+ * Resets the messages that get rendered if the REST API Server or the Qpid broker fail.
+ */
+ var resetErrorMessages = function() {
+ $("#restapi-disconnected").hide();
+ $("#broker-disconnected").hide();
+ $("#failed-to-connect").hide();
+ };
+
+ /**
+ * Show Rest API Disconnected Message, hide the others.
+ */
+ var showRestAPIDisconnected = function() {
+ resetErrorMessages();
+ $("#restapi-disconnected").show();
+ };
+
+ /**
+ * Show Broker Disconnected Message, hide the others.
+ */
+ var showBrokerDisconnected = function() {
+ resetErrorMessages();
+ $("#broker-disconnected").show();
+ };
+
+ /**
+ * Show Failed to Connect Message, hide the others.
+ */
+ var showFailedToConnect = function() {
+ resetErrorMessages();
+ $("#failed-to-connect").show();
+ };
+
+ /**
+ * QMF2 EventHandler that we register with the QMF2 Console.
+ * @param workItem a QMF2 API WorkItem.
+ */
+ var onEvent = function(workItem) {
+ if (workItem._type == "AGENT_DELETED") {
+ var agent = workItem._params.agent;
+
+ if (agent._product == "qpidd" && _connection != null) {
+ if (_receivedData) {
+ showBrokerDisconnected();
+ } else {
+ showFailedToConnect();
+ }
+ } else if (agent._product == "qpid.restapi") {
+ showRestAPIDisconnected();
+ }
+ } else {
+ _receivedData = true;
+ resetErrorMessages();
+ if (workItem._type == "EVENT_RECEIVED") {
+ qmfui.Events.update(workItem);
+ }
+ }
+
+ // onEvent() will be called periodically by the broker heartbeat events, so we use that fact to trigger
+ // a call to getAllObjects() which will itself trigger a call to updateState() when its results return.
+ getAllObjects();
+ };
+
+ /**
+ * This method is called if startConsole() has been called with disableEvents. In this state
+ * the onEvent() method won't be triggered by the QMF2 callback so we need to explicitly poll via a timer.
+ */
+ var pollForData = function() {
+ if (_connection != null && _disableEvents) {
+ _polling = true;
+ getAllObjects();
+ setTimeout(function() {
+ pollForData();
+ }, qmf.REFRESH_PERIOD);
+ } else {
+ _polling = false;
+ }
+ };
+
+ /**
+ * This method is called by the failure handler of getAllObjects(). If it is triggered it means there has
+ * been some form of Server side disconnection. If this occurs set an error banner then attempt to re-open
+ * the Qpid Connection. If the Connection reopens successfully updateState() will start getting called again.
+ * This method returns immediately if _disableEvents is false because the underlying QMF Console has its own
+ * reconnection logic in its Event dispatcher, which we only need to replicate if that is disabled.
+ * @param xhr the jQuery XHR object.
+ */
+ var timeout = function(xhr) {
+ if (_disableEvents) {
+ if (xhr.status == 0) {
+ showRestAPIDisconnected();
+ } else {
+ if (_receivedData) {
+ showBrokerDisconnected();
+ } else {
+ showFailedToConnect();
+ }
+ if (xhr.status == 404 && _connection != null && _connection.open) {
+ _connection.open();
+ }
+ }
+ }
+ };
+
+ /**
+ * This method is called when getAllObjects() completes, that is to say when all of the asynchronous responses
+ * for the Deferred XHR objects returned by getObjects() have all returned successfully. This method triggers
+ * the update() method on each of the user interface pages.
+ */
+ var updateState = function() {
+ _receivedData = true;
+ resetErrorMessages();
+
+ qmfui.Broker.update();
+ qmfui.Connections.update();
+ qmfui.Exchanges.update();
+ qmfui.Queues.update();
+ //qmfui.Links.update(); // TODO
+ //qmfui.RouteTopology.update(); // TODO
+
+ // Update sub-pages after main pages as these may require state (such as statistics) set in the main pages.
+ qmfui.SelectedConnection.update();
+ qmfui.SelectedQueue.update();
+ qmfui.QueueSubscriptions.update();
+ qmfui.ConnectionSubscriptions.update();
+ qmfui.SelectedExchange.update();
+ qmfui.Bindings.update();
+ qmfui.Graphs.update();
+ };
+
+ /**
+ * This method retrieves the QmfConsoleData Objects from the real QMF Console via AJAX calls to the REST API.
+ * Because the AJAX calls are all asynchronous we use jQuery.when(), which provides a way to execute callback
+ * functions based on one or more objects, usually Deferred objects that represent asynchronous events.
+ * See http://api.jquery.com/jQuery.when/ and http://api.jquery.com/deferred.then/
+ */
+ var getAllObjects = function() {
+ $.when(
+ _console.getObjects("broker", function(data) {_objects.broker = data;}),
+ _console.getObjects("queue", function(data) {_objects.queue = data;}),
+ _console.getObjects("exchange", function(data) {_objects.exchange = data;}),
+ _console.getObjects("binding", function(data) {_objects.binding = data;}),
+ _console.getObjects("subscription", function(data) {_objects.subscription = data;}),
+ _console.getObjects("connection", function(data) {_objects.connection = data;}),
+// _console.getObjects("link", function(data) {_objects.link = data;}),
+// _console.getObjects("bridge", function(data) {_objects.bridge = data;}),
+ _console.getObjects("session", function(data) {_objects.session = data;})
+ ).then(updateState, timeout);
+ };
+
+ /**
+ * Handle the load event, triggered when the document has completely loaded.
+ */
+ var loadHandler = function() {
+ qmfui.Console.startConsole(0); // Start the default QMF Console Connection.
+ };
+
+ /**
+ * Handle the unload event, triggered when the document unloads or we navigate off the page. It's not 100%
+ * reliable, which is a shame as it's the best way to clear up Server state. If it fails the Server will
+ * eventually clear up unused Connections after a timeout period. TODO Opera seems to be especially bad at
+ * firing the unloadHandler, not sure why this is, something to look into.
+ * @param event the event that triggered the unloadHandler.
+ */
+ var unloadHandler = function(event) {
+ // For mobile Safari (at least) we get pagehide events when navigating off the page, but also when closing via
+ // home or locking the device. Fortunately this case has the persisted flag set as we don't want to close then.
+ var persisted = (event.type == "pagehide") ? event.originalEvent.persisted : false;
+ if (!persisted) {
+ qmfui.Console.stopConsole();
+ }
+ };
+
+ /**
+ * Callback handler triggered when _console.addConnection() fails. This should only occur if an actual
+ * exception occurs on the REST API Server due to invalid connectionOptions.
+ */
+ var handleConnectionFailure = function() {
+ qmfui.Console.stopConsole();
+ showFailedToConnect();
+ }
+
+ // ******************************************* Accessor Methods *******************************************
+
+ /**
+ * Retrieve the broker Management Object, optionally as a QmfConsoleData Object (with invokeMethod attached).
+ * @param makeConsoleData if true attach the invokeMethod method to the returned Management Object.
+ * @return the QMF broker Management Object optionally as a QmfConsoleData.
+ */
+ this.getBroker = function(makeConsoleData) {
+ var brokers = _objects.broker;
+
+ if (brokers == null || brokers.length == 0) {
+ // Return a fake QmfConsoleData Object with an invokeMethod that calls the callback handler with a
+ // response object containing error_text. It is actually pretty uncommon for the brokers array to
+ // be empty so this approach allows us to call invokeMethod without lots of checking for broker == null.
+ return {invokeMethod: function(name, inArgs, handler) {
+ handler({"error_text" : "Could not retrieve broker Management Object"});
+ }};
+ } else {
+ var broker = brokers[0];
+ if (makeConsoleData) {
+ _console.makeConsoleData(broker);
+ }
+ return broker;
+ }
+ };
+
+ /**
+ * These methods are basic accessors returning the cached lists of QmfData objects returned by getObjects()
+ */
+ this.getQueues = function() {
+ return _objects.queue;
+ };
+
+ this.getExchanges = function() {
+ return _objects.exchange;
+ };
+
+ this.getBindings = function() {
+ return _objects.binding;
+ };
+
+ this.getSubscriptions = function() {
+ return _objects.subscription;
+ };
+
+ this.getConnections = function() {
+ return _objects.connection;
+ };
+
+ this.getSessions = function() {
+ return _objects.session;
+ };
+
+/* TODO
+ this.getLinks = function() {
+ return _objects.link;
+ };
+
+ this.getBridges = function() {
+ return _objects.bridge;
+ };
+*/
+
+ /**
+ * Calls the underlying QMF Console's makeConsoleData(). This call turns a QmfData object into a QmfConsoleData
+ * object, which adds methods such as invokeMethod() to the object.
+ * @param the object that we want to turn into a QmfConsoleData.
+ */
+ this.makeConsoleData = function(object) {
+ _console.makeConsoleData(object);
+ };
+
+ /**
+ * @return the list of QMF Console Connections that the user is interested in. The returned list is a list of
+ * objects containing url, name and connectionOptions properties.
+ */
+ this.getConsoleConnectionList = function() {
+ return this.consoleConnections;
+ };
+
+ /**
+ * Note that in the following it's important to note that there is separation between adding/removing
+ * Console Connections and actually starting/stopping Console Connections, this is because a user may wish
+ * to add several QMF Console Connections to point to a number of different brokers before actually
+ * chosing to connect to a particular broker. Similarly a user may wish to delete a QMF Console Connection
+ * from the list (s)he is interested in independently from selecting a new connection.
+ */
+
+ /**
+ * Append a new Console Connection with the specified url, name and connectionOptions to the end of the
+ * list of QMF Console Connections the the user many be interested in. Note that this method *does not*
+ * actually start a connection to the new console for that we must call the startConsole() method.
+ * The name supplied in this method is simply a user friendly name and is not related to the name that
+ * may be applied to the Connection when it is stored on the REST API, that name is really best considered
+ * as an opaque "handle" and is intended to be unique for each connection.
+ *
+ * @param name a user friendly name for the Console Connection.
+ * @param url the broker Connection URL in one of the formats supported by the Java ConnectionHelper class
+ * namely an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Java Connection URL.
+ * @param connectionOptions a JSON string containing the Connection Options in the same form as used
+ * in the qpid::messaging API.
+ */
+ this.addConsoleConnection = function(name, url, connectionOptions, disableEvents) {
+ if (disableEvents) {
+ this.consoleConnections.push({name: name, url: url, connectionOptions: connectionOptions,
+ disableEvents: true});
+ } else {
+ this.consoleConnections.push({name: name, url: url, connectionOptions: connectionOptions});
+ }
+ };
+
+ /**
+ * Remove the Console Connection specified by the index. Note that this method *does not* actually stop
+ * a connection to the console for that we must call the stopConsole() method.
+ * @param index the index of the Console Connection that we want to remove.
+ */
+ this.removeConsoleConnection = function(index) {
+ if (_activeConsoleConnection > index) {
+ _activeConsoleConnection--;
+ }
+ this.consoleConnections.splice(index, 1); // remove a single array item at the specified index.
+ };
+
+ /**
+ * Actually start the Qpid Connection and QMF Console for the Console Connection stored at the specified index.
+ * When the QMF Console successfully starts it will start sending QMF Events and updating the Management
+ * Objects automatically, this will in turn cause the User Interface pages to refresh.
+ * Alternatively if QMF Event delivery is disabled this method initiates the pollForData().
+ * @param index the index of the Console Connection that we wish to start. Index zero is the default Console.
+ */
+ this.startConsole = function(index) {
+ var connection = this.consoleConnections[index];
+
+ // Using a Connection URL of "" makes the REST API use its default configured broker connection.
+ var factory = new qpid.ConnectionFactory(connection.url, connection.connectionOptions);
+ _connection = factory.createConnection();
+
+ // Initialise QMF Console
+ _console = new qmf.Console(onEvent);
+ if (connection.disableEvents != null) {
+ _disableEvents = true;
+ _console.disableEvents();
+ } else {
+ _disableEvents = false;
+ }
+
+ _receivedData = false;
+ _console.addConnection(_connection, handleConnectionFailure);
+ _activeConsoleConnection = index;
+
+ // If disableEvents is set we have to use a timed poll to get the Management Objects. We check if the polling
+ // loop is already running, because if we try and start it multiple times we may get spurious refreshes.
+ if (_disableEvents && !_polling) {
+ pollForData();
+ }
+ };
+
+ /**
+ * Stops the currently running Console Connection and closes the Qpid Connection. This will result in the
+ * underlying Connection object on the REST API Server getting properly cleaned up. It's not essential
+ * to call stopConsole() before a call to startConsole() as the server Connection objects will eventually
+ * time out, but it's good practice to do it if at all possible.
+ */
+ this.stopConsole = function() {
+ if (_console) {
+ _console.destroy();
+ }
+
+ if (_connection) {
+ _connection.close();
+ _connection = null;
+ }
+ };
+
+ /**
+ * @return the index of the currently active (connected) QMF Console Connection.
+ */
+ this.getActiveConsoleConnection = function() {
+ return _activeConsoleConnection;
+ };
+
+ // *********************** Initialise class when the DOM loads using jQuery.ready() ***********************
+ $(function() {
+ // Create a fake logging console for browsers that don't have a real console.log - only for debugging.
+ if (!window.console) {
+ /* // A slightly hacky console.log() to help with debugging on old versions of IE.
+ console = window.open("", "console", "toolbar, menubar, status, width=500, height=500, scrollbars=yes");
+ console.document.open("text/plain");
+ console.log = function(text) {console.document.writeln(text);};*/
+
+ console = {log: function(text) {}}; // Dummy to avoid bad references in case logging accidentally added.
+ }
+
+ // Add a default show handler. Pages that bind update() to show should remove this by doing unbind("show").
+ $(".main").bind("show", function() {$("#resource-deleted").hide();});
+
+ // pagehide and unload each work better than the other in certain circumstances so we trigger on both.
+ $(window).bind("unload pagehide", unloadHandler);
+
+ // Iterate through each page calling its initialise method if one is present.
+ for (var i in qmfui) {
+ if (qmfui[i].initialise) {
+ qmfui[i].initialise();
+ }
+ }
+
+ // Send a synthesised click event to the settings-tab element to select the settings page on startup.
+ // We check if the left property of the main class is zero, if it is then the sidebar has been expanded
+ // to become the main menu (e.g. for mobile devices) otherwise we show the settings page.
+ if (parseInt($(".main").css('left'), 10) != 0) {
+ $("#settings-tab").click();
+ }
+
+ // Hide the splash page.
+ $("#splash").hide();
+ });
+
+ $(window).load(loadHandler);
+}; // End of qmfui.Console definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Configure Settings
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Settings class managing the id="settings" page.
+ */
+qmfui.Settings = new function() {
+ /**
+ * Show the Settings page, rendering any dynamic content if necessary.
+ */
+ var show = function() {
+ // Retrieve the currently configured QMF Console Connections.
+ var qmfConsoleConnections = qmfui.Console.getConsoleConnectionList();
+
+ iTablet.renderList($("#qmf-console-selector"), function(i) {
+ var qmfConsoleConnection = qmfConsoleConnections[i];
+ var name = qmfConsoleConnection.name;
+ var url = qmfConsoleConnection.url;
+ url = (url == null || url == "") ? "" : " (" + url + ")";
+ var label = (name == null || name == "") ? url : name + url;
+ var checked = (i == qmfui.Console.getActiveConsoleConnection()) ? "checked" : "";
+
+ return "<li class='arrow'><label for='qmf-console" + i + "'>" + label + "</label><input type='radio' id='qmf-console" + i + "' name='qmf-console-selector' value='" + i + "' " + checked + "/><a href='#selected-qmf-console-connection?index=" + i + "'></a></li>";
+ }, qmfConsoleConnections.length);
+
+ $("#qmf-console-selector input").change(changeConsole);
+ };
+
+ /**
+ * If the settings-hide-qmf-objects checkbox gets changed refresh the Queues and Exchanges pages to reflect this.
+ */
+ var changeHideQmf = function() {
+ qmfui.Queues.update();
+ qmfui.Exchanges.update();
+ };
+
+ /**
+ * Handles changes to the Console selection Radio buttons. If a change occurs the Console Connection is stopped
+ * and the newly selected Console Connection is started (we chose based on the index into the list)
+ */
+ var changeConsole = function() {
+ qmfui.Console.stopConsole();
+ qmfui.Console.startConsole($(this).val());
+ };
+
+ this.initialise = function() {
+ $("#settings").bind("show", show);
+ $("#settings-hide-qmf-objects").change(changeHideQmf);
+ };
+}; // End of qmfui.Settings definition
+
+
+/**
+ * Create a Singleton instance of the AddConsoleConnection class managing the id="add-console-connection" page.
+ */
+qmfui.AddConsoleConnection = new function() {
+ var submit = function() {
+ var consoleURL = $("#console-url");
+
+ // Check that a URL value has been supplied. TODO Probably worth doing some validation that the supplied
+ // Connection URL is at least syntactically valid too.
+ var url = consoleURL.val();
+ if (url == "") {
+ consoleURL.addClass("error");
+ return;
+ } else {
+ consoleURL.removeClass("error");
+ }
+
+ var name = $("#console-name").val();
+ try {
+ var connectionOptions = $.parseJSON($("#add-connection-options textarea").val());
+ // TODO worth checking that the connection options are valid and in a usable format. Connection Options
+ // is still a bit of a work in progressed. though it seems to work fine if sensible options are used.
+ qmfui.Console.addConsoleConnection(name, url, connectionOptions, $("#console-disable-events")[0].checked);
+ iTablet.location.back();
+ } catch(e) {
+ setTimeout(function() {
+ alert("Connection Options must be entered as a well-formed JSON string.");
+ return;
+ }, 0);
+ }
+ };
+
+ this.initialise = function() {
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#add-console-connection .right.button").bind(qmfui.END_EV, submit);
+ };
+}; // End of qmfui.AddConsoleConnection definition
+
+
+/**
+ * Create a Singleton instance of the SelectedQMFConsoleConnection class managing the
+ * id="selected-qmf-console-connection" page.
+ */
+qmfui.SelectedQMFConsoleConnection = new function() {
+ var _index = null;
+ var _name = "";
+ var _url = "";
+
+ /**
+ * This method deletes the selected QMFConsoleConnection.
+ */
+ var deleteHandler = function() {
+ // Flag to check if the Console we're trying to delete is the currently selected/connected one.
+ var currentlySelected = ($("#qmf-console-selector input[checked]").val() == _index);
+
+ // Text for the confirm dialogue with additional wording if it's currently connected.
+ var confirmText = 'Delete QMF Connection "' + _name + '" to ' + _url + '?';
+ confirmText += currentlySelected ? "\nNote that this is the current active Connection, so deleting it will cause a reconnection to the default Connection." : ""
+
+ // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice.
+ // Calling confirm within a timeout ensures things are placed correctly onto the event queue.
+ setTimeout(function() {
+ if (confirm(confirmText) == false) {
+ return;
+ } else {
+ qmfui.Console.removeConsoleConnection(_index);
+ // If the QMF Console Connection being deleted is the currently connected one we stop the Console
+ // and establish a connection to the default QMF Console Connection.
+ if (currentlySelected) {
+ qmfui.Console.stopConsole();
+ qmfui.Console.startConsole(0); // Start the default QMF Console Connection.
+ }
+
+ iTablet.location.back(); // Navigate to the previous page.
+ }
+ }, 0);
+ };
+
+ var show = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#selected-qmf-console-connection") {
+ return;
+ }
+
+ // Get the selected QMFConsoleConnection
+ _index = parseInt(data.index); // The parseInt is important! Without it the index lookup gives odd results..
+ var qmfConsoleConnections = qmfui.Console.getConsoleConnectionList();
+ var qmfConsoleConnection = qmfConsoleConnections[_index];
+ _name = qmfConsoleConnection.name;
+ _url = qmfConsoleConnection.url;
+ var connectionOptions = qmfConsoleConnection.connectionOptions;
+
+ var eventsDisabled = false;
+ if (qmfConsoleConnection.disableEvents != null) {
+ eventsDisabled = qmfConsoleConnection.disableEvents;
+ }
+
+ // If the selected Console is the default one hide the delete button, otherwise show it.
+ if (_index == 0) {
+ $("#selected-qmf-console-connection .header a.delete").hide();
+ } else {
+ $("#selected-qmf-console-connection .header a.delete").show();
+ }
+
+ // Populate the page header with the Console Connection name/url.
+ var urlText = (_url == null || _url == "") ? "" : " (" + _url + ")";
+ var label = (_name == null || _name == "") ? urlText : _name + urlText;
+ $("#selected-qmf-console-connection .header h1").text(label);
+
+ $("#selected-qmf-console-connection-url p").text(((_url == "") ? 'default' : _url));
+ $("#selected-qmf-console-connection-name p").text(((_name == "") ? '""' : _name));
+ $("#selected-qmf-console-connection-events-disabled p").text(eventsDisabled);
+
+ if (_url == "") {
+ $("#selected-qmf-console-connection-default-info").show();
+ } else {
+ $("#selected-qmf-console-connection-default-info").hide();
+ }
+
+ if (connectionOptions == "") {
+ $("#selected-qmf-console-connection-connection-options").hide();
+ } else {
+ $("#selected-qmf-console-connection-connection-options textarea").val(util.stringify(connectionOptions));
+ $("#selected-qmf-console-connection-connection-options").show();
+ }
+ };
+
+ this.initialise = function() {
+ $("#selected-qmf-console-connection").unbind("show").bind("show", show);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#selected-qmf-console-connection .header a.delete").bind(qmfui.END_EV, deleteHandler);
+ };
+}; // End of qmfui.SelectedQMFConsoleConnection definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Broker Information
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Broker class managing the id="broker" page.
+ */
+qmfui.Broker = new function() {
+ /**
+ * Convert nanoseconds into hours, minutes and seconds.
+ */
+ var convertTime = function(ns) {
+ var milliSecs = ns/1000000;
+ var msSecs = (1000);
+ var msMins = (msSecs * 60);
+ var msHours = (msMins * 60);
+ var numHours = Math.floor(milliSecs/msHours);
+ var numMins = Math.floor((milliSecs - (numHours * msHours)) / msMins);
+ var numSecs = Math.floor((milliSecs - (numHours * msHours) - (numMins * msMins))/ msSecs);
+ numSecs = numSecs < 10 ? numSecs = "0" + numSecs : numSecs;
+ numMins = numMins < 10 ? numMins = "0" + numMins : numMins;
+
+ return (numHours + ":" + numMins + ":" + numSecs);
+ };
+
+ this.update = function() {
+ var broker = qmfui.Console.getBroker();
+
+ // Render the selected broker properties to #broker-list.
+ var keys = ["name", "version", "uptime", "port", "maxConns", "connBacklog", "dataDir",
+ "mgmtPublish", "mgmtPubInterval", "workerThreads",
+ /* 0.20 publishes many more stats so include them if available */
+ "queueCount", "acquires", "releases", "abandoned", "abandonedViaAlt"];
+ iTablet.renderList($("#broker-list"), function(i) {
+ var key = keys[i];
+ var value = broker[key];
+ if (value == null) { // Only show statistics that are actually available (later brokers publish more stats)
+ return false;
+ } else {
+ if (key == "uptime") {
+ value = convertTime(value); // Convert uptime to a more human readable value
+ }
+ return "<li><a href='#'>" + key + "<p>" + value + "</p></a></li>";
+ }
+ }, keys.length);
+
+ // Render a number of 0.20 statistics in their own subsections to improve readability.
+
+ // Render the Message Input Output Statistics.
+ if (broker.msgDepth == null) {
+ $("#broker-msgio-container").hide();
+ } else {
+ $("#broker-msgio-container").show();
+ keys = ["msgDepth", "msgTotalEnqueues", "msgTotalDequeues"];
+ iTablet.renderList($("#broker-msgio"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + broker[key] + "</p></a></li>";
+ }, keys.length);
+ }
+
+ // Render the Byte Input Output Statistics.
+ if (broker.byteDepth == null) {
+ $("#broker-byteio-container").hide();
+ } else {
+ $("#broker-byteio-container").show();
+ keys = ["byteDepth", "byteTotalEnqueues", "byteTotalDequeues"];
+ iTablet.renderList($("#broker-byteio"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + broker[key] + "</p></a></li>";
+ }, keys.length);
+ }
+
+ var hideDetails = $("#settings-hide-details")[0].checked;
+
+ // Render the Flow-to-disk Statistics.
+ if (broker.msgFtdDepth == null || hideDetails) {
+ $("#broker-flow-to-disk-container").hide();
+ } else {
+ $("#broker-flow-to-disk-container").show();
+ keys = ["msgFtdDepth", "msgFtdEnqueues", "msgFtdDequeues",
+ "byteFtdDepth", "byteFtdEnqueues", "byteFtdDequeues"];
+ iTablet.renderList($("#broker-flow-to-disk"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + broker[key] + "</p></a></li>";
+ }, keys.length);
+ }
+
+ // Render the Dequeue Details.
+ if (broker.discardsTtl == null || hideDetails) {
+ $("#broker-dequeue-container").hide();
+ } else {
+ $("#broker-dequeue-container").show();
+ keys = ["discardsTtl", "discardsRing", "discardsLvq", "discardsOverflow",
+ "discardsSubscriber", "discardsPurge", "reroutes"];
+ iTablet.renderList($("#broker-dequeue"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + broker[key] + "</p></a></li>";
+ }, keys.length);
+ }
+ };
+
+ /**
+ * This click handler is triggered by a click on the broker-log-level radio button. It invokes the QMF
+ * setLogLevel method to set the log level of the connected broker to debug or normal.
+ */
+ var setLogLevel = function(e) {
+ var level = $(e.target).val();
+
+ // Set to the QMF2 levels for broker debug and normal.
+ level = (level == "debug") ? "debug+:Broker" : "notice+";
+
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("setLogLevel", {"level": level}, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ }
+ });
+ };
+
+ this.initialise = function() {
+ // Explicitly using a click handler rather than change as it's possible that another instance has changed
+ // the log level so we may want to be able to reset it by clicking the currently selected level.
+ $("#broker-log-level li input").click(setLogLevel);
+ };
+}; // End of qmfui.Broker definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Connection Information
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Connections class managing the id="connections" page.
+ */
+qmfui.Connections = new function() {
+ var _connectionMap = {}; // Connections indexed by ObjectId.
+ var _sessionMap = {}; // Sessions indexed by ObjectId.
+ var _subscriptionMap = {}; // Subscriptions indexed by ObjectId.
+ var _queueToSubscriptionAssociations = {}; // 0..* association between Queue and Subscription keyed by Queue ID.
+
+ /**
+ * Return the Connection object indexed by QMF ObjectId.
+ */
+ this.getConnection = function(oid) {
+ return _connectionMap[oid];
+ };
+
+ /**
+ * Return the Session object indexed by QMF ObjectId.
+ */
+ this.getSession = function(oid) {
+ return _sessionMap[oid];
+ };
+
+ /**
+ * Return the Subscription object indexed by QMF ObjectId.
+ */
+ this.getSubscription = function(oid) {
+ return _subscriptionMap[oid];
+ };
+
+ /**
+ * Return the Subscription association List indexed by a queue's QMF ObjectId.
+ */
+ this.getQueueSubscriptions = function(oid) {
+ var subs = _queueToSubscriptionAssociations[oid];
+ return (subs == null) ? [] : subs; // If it's null set it to an empty array.
+ };
+
+ /**
+ * The Connections update method includes a number of subtle complexities due to the way QMF Management
+ * Objects are associated with each other. For example a Subscription is associated with a single
+ * Session however a Session may have zero or more Subscriptions, similarly a Session is associated with
+ * a single Connection but a Connection may have zero or more Sessions.
+ *
+ * The QMF Management Objects maintain the single unidirectional associations, which generally makes sense
+ * but an unfortunate side-effect of this is that if one wishes to obtain information about Sessions and
+ * Subscriptions related to a given Connection it's somewhat of a pain as one has to do a multi-pass dereference.
+ *
+ * This method does the dereferencing and creates a 0..* association to Session in each Connection object and
+ * a 0..* association to Subscription in each Session object so other pages can avoid their own dereferencing.
+ * N.B. these added associations are references to actual Session or Subscription objects and NOT via ObjectIds
+ * This is because these associations are not *really* QmfData object properties and only exist within the local
+ * memory space of this application, so using actual memory references avoids an additional dereference.
+ */
+ this.update = function() {
+ _subscriptionMap = {}; // Clear _subscriptionMap.
+ _sessionMap = {}; // Clear _sessionMap.
+ _queueToSubscriptionAssociations = {}; // Clear _queueToSubscriptionAssociations.
+
+ var subscriptions = qmfui.Console.getSubscriptions();
+ for (var i in subscriptions) {
+ var subscription = subscriptions[i];
+ var subscriptionId = subscription._object_id;
+ var sessionRef = subscription.sessionRef;
+ var queueRef = subscription.queueRef;
+
+ // Create the Session->Subscriptions association array and store it keyed by the sessionRef, when we go
+ // to store the actual Session we can retrieve the association and store it as a property of the Session.
+ if (_sessionMap[sessionRef] == null) {
+ _sessionMap[sessionRef] = [subscription];
+ } else {
+ _sessionMap[sessionRef].push(subscription);
+ }
+
+ // Create the Queue->Subscriptions association array and store it keyed by the queueRef, when we go
+ // to store the actual Session we can retrieve the association and store it as a property of the Session.
+ if (_queueToSubscriptionAssociations[queueRef] == null) {
+ _queueToSubscriptionAssociations[queueRef] = [subscription];
+ } else {
+ _queueToSubscriptionAssociations[queueRef].push(subscription);
+ }
+
+ _subscriptionMap[subscriptionId] = subscription; // Index subscriptions by ObjectId.
+ }
+
+ var connectionToSessionAssociations = {};
+ var sessions = qmfui.Console.getSessions();
+ for (var i in sessions) {
+ var session = sessions[i];
+ var sessionId = session._object_id;
+ var connectionRef = session.connectionRef;
+
+ var subs = _sessionMap[sessionId]; // Retrieve the association array and store it as a property.
+ subs = (subs == null) ? [] : subs; // If it's null set it to an empty array.
+ session._subscriptions = subs;
+
+ // Create the Connection->Sessions association array and store it keyed by the connectionRef, when we go to
+ // store the actual Connection we can retrieve the association and store it as a property of the Connection.
+ if (connectionToSessionAssociations[connectionRef] == null) {
+ connectionToSessionAssociations[connectionRef] = [session];
+ } else {
+ connectionToSessionAssociations[connectionRef].push(session);
+ }
+ _sessionMap[sessionId] = session; // Index sessions by ObjectId.
+ }
+
+ // Temporary connections map, we move active connections to this so deleted connections wither and die.
+ var temp = {};
+ var connections = qmfui.Console.getConnections();
+ iTablet.renderList($("#connections-list"), function(i) {
+ var connection = connections[i];
+ var connectionId = connection._object_id;
+
+ // Look up the previous value for the indexed connection using its objectId.
+ var prev = _connectionMap[connectionId];
+ var stats = (prev == null) ? new qmfui.Statistics(["msgsFromClient", "msgsToClient"]) : prev._statistics;
+ stats.put([connection.msgsFromClient, connection.msgsToClient, connection._update_ts]);
+ connection._statistics = stats;
+
+ // Retrieve the association array and store it as a property.
+ var sessions = connectionToSessionAssociations[connectionId];
+ sessions = (sessions == null) ? [] : sessions; // If it's null set it to an empty array.
+ connection._sessions = sessions;
+ temp[connectionId] = connection;
+
+ // Calculate the total number of subscriptions for this connection, this is useful because a count of
+ // zero indicates that a connection is probably a producer only connection.
+ var connectionSubscriptions = 0;
+ for (var i in connection._sessions) {
+ var session = connection._sessions[i];
+ connectionSubscriptions += session._subscriptions.length;
+ }
+
+ var address = connection.address + " (" + connection.remoteProcessName + ")";
+ if (connectionSubscriptions == 0) {
+ return "<li class='arrow'><a href='#selected-connection?id=" + connectionId + "'>" + address +
+ "<p>No Subscriptions</p></a></li>";
+ } else {
+ return "<li class='arrow'><a href='#selected-connection?id=" + connectionId + "'>" + address +
+ "</a></li>";
+ }
+ }, connections.length);
+
+ // Replace the saved statistics with the newly populated temp instance, which only has active objects
+ // moved to it, this means that any deleted objects are no longer present.
+ _connectionMap = temp;
+ };
+
+}; // End of qmfui.Connections definition
+
+
+/**
+ * Create a Singleton instance of the SelectedConnection class managing the id="selected-connection" page.
+ */
+qmfui.SelectedConnection = new function() {
+ var _sessions = []; // Populate this with the ID of matching sessions enabling navigation to sessions.
+
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#selected-connection") {
+ return;
+ }
+
+ // Get the latest statistics update of the selected connection object.
+ var connectionId = data.id;
+ var connection = qmfui.Connections.getConnection(connectionId);
+ if (connection == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ var name = connection.address + " (" + connection.remoteProcessName + ")";
+ $("#selected-connection .header h1").text(name);
+
+ // Populate the back button with "Subscription" or "Connections" depending on context
+ var backText = data.fromSubscription ? "Subscrip..." : "Connect...";
+
+ // Using $("#selected-connection .header a").text(backText) wipes all child elements so use the following.
+ $("#selected-connection .header a")[0].firstChild.nodeValue = backText;
+
+ // Render the connection message statistics to #selected-connection-msgio
+ var keys = ["msgsFromClient", "msgsToClient"];
+ iTablet.renderList($("#selected-connection-msgio"), function(i) {
+ var key = keys[i];
+ return "<li class='arrow'><a href='#graphs?connectionId=" + connectionId + "&property=" + i + "'>" +
+ key + "<p>" + connection[key] + "</p></a></li>";
+ }, keys.length);
+
+ // Render the connection byte statistics to #selected-connection-byteio
+ keys = ["bytesFromClient", "bytesToClient"];
+ iTablet.renderList($("#selected-connection-byteio"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + connection[key] + "</p></a></li>";
+ }, keys.length);
+
+ // Render the connection frame statistics to #selected-connection-frameio
+ keys = ["framesFromClient", "framesToClient"];
+ iTablet.renderList($("#selected-connection-frameio"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + connection[key] + "</p></a></li>";
+ }, keys.length);
+
+ // Render selected general connection properties to #selected-connection-general.
+ keys = ["federationLink","SystemConnection","incoming", "authIdentity", "userProxyAuth",
+ "saslMechanism", "saslSsf", "remotePid", "shadow", "closing", "protocol"];
+ iTablet.renderList($("#selected-connection-general"), function(i) {
+ var key = keys[i];
+ var value = connection[key];
+ if (value == null) {
+ return false;
+ } else {
+ return "<li><a href='#'>" + key + "<p>" + value + "</p></a></li>";
+ }
+ }, keys.length);
+
+ // Render links to the sessions associated with this connection.
+ _sessions = connection._sessions;
+ if (_sessions.length == 0) { // Show a message if there are no sessions at all
+ $("#selected-connection-subscribed-sessions").hide();
+ $("#selected-connection-subscribed-sessions").prev().hide();
+ $("#selected-connection-unsubscribed-sessions").show();
+ $("#selected-connection-unsubscribed-sessions").prev().show();
+ iTablet.renderList($("#selected-connection-unsubscribed-sessions"), function(i) {
+ return "<li class='grey'><a href='#'>There are currently no sessions attached to " +
+ name + "</a></li>";
+ });
+ } else {
+ var subscribed = [];
+ var unsubscribed = [];
+ for (var i in _sessions) {
+ var session = _sessions[i];
+ var id = session._object_id;
+ var subscriptionCount = session._subscriptions.length;
+ if (subscriptionCount == 0) {
+ unsubscribed.push("<li><a href='#'>" + session.name + "</a></li>");
+ } else {
+ var plural = subscriptionCount > 1 ? " Subscriptions" : " Subscription";
+ subscribed.push("<li class='multiline arrow'><a href='#connection-subscriptions?id=" + id + "'><div>" +
+ session.name + "<p class='sub'>" + subscriptionCount + plural + "</p></div></a></li>");
+ }
+ }
+
+ if (subscribed.length > 0) {
+ $("#selected-connection-subscribed-sessions").show();
+ $("#selected-connection-subscribed-sessions").prev().show();
+ iTablet.renderList($("#selected-connection-subscribed-sessions"), function(i) {
+ return subscribed[i];
+ }, subscribed.length);
+ } else {
+ $("#selected-connection-subscribed-sessions").hide();
+ $("#selected-connection-subscribed-sessions").prev().hide();
+ }
+
+ if (unsubscribed.length > 0) {
+ $("#selected-connection-unsubscribed-sessions").show();
+ $("#selected-connection-unsubscribed-sessions").prev().show();
+ iTablet.renderList($("#selected-connection-unsubscribed-sessions"), function(i) {
+ return unsubscribed[i];
+ }, unsubscribed.length);
+ } else {
+ $("#selected-connection-unsubscribed-sessions").hide();
+ $("#selected-connection-unsubscribed-sessions").prev().hide();
+ }
+ }
+ }
+ };
+
+ this.initialise = function() {
+ $("#selected-connection").unbind("show").bind("show", qmfui.SelectedConnection.update);
+ };
+}; // End of qmfui.SelectedConnection definition
+
+
+/**
+ * Create a Singleton instance of the ConnectionSubscriptions class managing the id="connection-subscriptions" page.
+ * This page is slightly different than most of the others as there can be multiple subscriptions and thus multiple
+ * arbitrary lists. Most pages have tried to reuse HTML list items for efficiency but in this page we clear and
+ * regenerate the contents of the page div each update as it's simpler than attempting to reuse elements.
+ */
+qmfui.ConnectionSubscriptions = new function() {
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#connection-subscriptions") {
+ return;
+ }
+
+ var sessionId = data.id;
+ var session = qmfui.Connections.getSession(sessionId);
+ if (session == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ var hideQmfObjects = $("#settings-hide-qmf-objects")[0].checked;
+
+ // Populate the page header with the session name.
+ $("#connection-subscriptions .header h1").text(session.name);
+
+ var subscriptions = session._subscriptions;
+ var length = subscriptions.length;
+
+ var page = $("#connection-subscriptions .page");
+ page.children().remove(); // Clear the contents of the page div.
+
+ for (var i = 0; i < length; i++) {
+ var subscription = subscriptions[i];
+ var id = subscription.queueRef;
+ var queue = qmfui.Queues.getQueue(id);
+
+ if (i == 0) {
+ page.append("<h1 class='first'>Subscription 1</h1>");
+ } else {
+ page.append("<h1>Subscription " + (i + 1) + "</h1>");
+ }
+
+ var name = $("<ul id='connection-subscription-name" + i + "' class='list'></ul>");
+ page.append(name);
+
+ // Render the associated queue name to #connection-subscription-name.
+ var isQmfQueue = queue._isQmfQueue;
+ iTablet.renderList(name, function(i) {
+ // If the associated Queue is a QNF Queue and hideQmfObjects has been selected render the
+ // Queue name grey and make it non-navigable otherwise render normally.
+ if (isQmfQueue && hideQmfObjects) {
+ return "<li class='grey'><a href='#selected-queue?id=" + id + "&fromSubscriptions=true'>" +
+ queue.name + "</a></li>";
+ } else {
+ return "<li class='arrow'><a href='#selected-queue?id=" + id + "&fromSubscriptions=true'>" +
+ queue.name + "</a></li>";
+ }
+ });
+
+ page.append("<p/>");
+
+ var list = $("<ul id='connection-subscription" + i + "' class='list'></ul>");
+ page.append(list);
+
+ // Render the useful subscription properties to #connection-subscriptions-list.
+ var keys = ["delivered", "browsing", "acknowledged", "exclusive", "creditMode"];
+ iTablet.renderList(list, function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + subscription[key] + "</p></a></li>";
+ }, keys.length);
+ }
+
+ $("#connection-subscriptions").trigger("refresh"); // Make sure touch scroller is up-to-date.
+ }
+ };
+
+ this.initialise = function() {
+ $("#connection-subscriptions").unbind("show").bind("show", qmfui.ConnectionSubscriptions.update);
+ };
+}; // End of qmfui.ConnectionSubscriptions definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Exchange Information
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Exchanges class managing the id="exchanges" page.
+ */
+qmfui.Exchanges = new function() {
+ var QMF_EXCHANGES = {"qmf.default.direct": true, "qmf.default.topic": true, "qpid.management": true};
+ var _exchangeNameMap = {}; // Exchanges indexed by name.
+ var _exchangeMap = {}; // Exchanges indexed by ObjectId.
+
+ /**
+ * Return the Exchange object for the given QMF ObjectId. The Exchange object contains the latest update
+ * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period.
+ */
+ this.getExchange = function(oid) {
+ return _exchangeMap[oid];
+ };
+
+ /**
+ * Return the Exchange object with the given name. The Exchange object contains the latest update
+ * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period.
+ */
+ this.getExchangeByName = function(name) {
+ return _exchangeNameMap[name];
+ };
+
+ this.update = function() {
+ var hideQmfObjects = $("#settings-hide-qmf-objects")[0].checked;
+
+ // We move active exchanges to temp so deleted exchanges wither and die. We can't just do _exchangeMap = {}
+ // as we need to retrieve and update statistics from any active (non-deleted) exchange.
+ var temp = {};
+ _exchangeNameMap = {}; // We can simply clear the map of exchanges indexed by name though.
+ var exchanges = qmfui.Console.getExchanges();
+ iTablet.renderList($("#exchanges-list"), function(i) {
+ var exchange = exchanges[i];
+
+ // Look up the previous value for the indexed exchange using its objectId.
+ var prev = _exchangeMap[exchange._object_id];
+ var stats = (prev == null) ? new qmfui.Statistics(["msgReceives", "msgRoutes", "msgDrops"]) :
+ prev._statistics;
+
+ stats.put([exchange.msgReceives, exchange.msgRoutes, exchange.msgDrops, exchange._update_ts]);
+ exchange._statistics = stats;
+
+ var id = exchange._object_id;
+ temp[id] = exchange;
+
+ var name = exchange.name;
+ name = (name == "") ? "'' (default direct)" : name;
+
+ _exchangeNameMap[name] = exchange;
+
+ if (QMF_EXCHANGES[name] && hideQmfObjects) {
+ return false; // Filter out any QMF related exchanges if the settings filter is checked.
+ } else {
+ return "<li class='arrow'><a href='#selected-exchange?id=" + id + "'>" + name +
+ "<p>" + exchange.type + "</p></a></li>";
+ }
+ }, exchanges.length);
+
+ // Replace the saved statistics with the newly populated temp instance, which only has active objects
+ // moved to it, this means that any deleted objects are no longer present.
+ _exchangeMap = temp;
+ };
+
+}; // End of qmfui.Exchanges definition
+
+
+/**
+ * Create a Singleton instance of the AddExchange class managing the id="add-exchange" page.
+ */
+qmfui.AddExchange = new function() {
+ // Protected Exchanges are exchanges that we don't permit binding to - default direct and the QMF exchanges.
+ var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true,
+ "qmf.default.topic": true, "qpid.management": true};
+
+ var _alternateExchangeName = "None (default)";
+
+ var submit = function() {
+ var properties = {};
+
+ if ($("#exchange-durable")[0].checked) {
+ properties["durable"] = true;
+ } else {
+ properties["durable"] = false;
+ }
+
+ if ($("#sequence")[0].checked) {
+ properties["qpid.msg_sequence"] = 1;
+ }
+
+ if ($("#ive")[0].checked) {
+ properties["qpid.ive"] = 1;
+ }
+
+ properties["exchange-type"] = $("#exchange-type input[checked]").val();
+
+ if (_alternateExchangeName != "None (default)") {
+ properties["alternate-exchange"] = _alternateExchangeName;
+ }
+
+ var exchangeName = $("#exchange-name");
+ var name = exchangeName.val();
+ if (name == "") {
+ exchangeName.addClass("error");
+ } else {
+ exchangeName.removeClass("error");
+
+ var arguments = {"type": "exchange", "name": name, "properties": properties};
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("create", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+ };
+
+ /**
+ * This method renders dynamic content in the AdditionalOptions page, it's really there to make sure that
+ * the AlternateExchange name gets properly rendered when it gets selected in the
+ * "#add-exchange-select-alternate-exchange" page.
+ */
+ var showAdditionalOptions = function() {
+ _alternateExchangeName = $("#add-exchange-select-alternate-exchange-list input[checked]").val();
+ var exchange = qmfui.Exchanges.getExchangeByName(_alternateExchangeName);
+ var exchangeType = (exchange == null) ? "" : exchange.type;
+ var typeText = (exchangeType == "") ? "" : " (" + exchangeType + ")";
+ $("#add-exchange-additional-alternate-exchange-name p").text(_alternateExchangeName + typeText);
+ };
+
+ /**
+ * This method renders the reroute-messages-select-exchange page when its show event is triggered. This page
+ * needs a show handler because it needs to be dynamically updated as the exchanges available in the radio
+ * button selection set will vary as exchanges get added or deleted.
+ */
+ var showSelectExchange = function() {
+ var exchanges = qmfui.Console.getExchanges();
+ var filteredExchanges = [];
+ var currentlySelected = $("#add-exchange-additional-alternate-exchange-name p").text();
+
+ // Check the status of any Exchange that the user may have previously selected prior to hitting "Done".
+ if (currentlySelected != "None (default)") {
+ // Remove the exchange type from the text before testing.
+ currentlySelected = currentlySelected.split(" (")[0];
+ if (qmfui.Exchanges.getExchangeByName(currentlySelected) == null) { // Check if it has been deleted.
+ alert('The currently selected Exchange "' + currentlySelected + '" appears to have been deleted.');
+ currentlySelected = "None (default)";
+ }
+ }
+
+ var checked = (currentlySelected == "None (default)") ? "checked" : "";
+ filteredExchanges.push("<li><label for='add-exchange-select-alternate-exchange-exchangeNone'>None (default)</label><input type='radio' id='add-exchange-select-alternate-exchange-exchangeNone' name='add-exchange-select-alternate-exchange' value='None (default)' " + checked + "/></li>");
+
+ var length = exchanges.length;
+ for (var i = 0; i < length; i++) {
+ var name = exchanges[i].name;
+ var type = exchanges[i].type;
+ checked = (currentlySelected == name) ? "checked" : "";
+
+ // Filter out default direct and QMF exchanges as we don't want to allow binding to those.
+ if (!PROTECTED_EXCHANGES[name]) {
+ filteredExchanges.push("<li><label for='add-exchange-select-alternate-exchange-exchange" + i + "'>" + name + " (" + type + ")</label><input type='radio' id='add-exchange-select-alternate-exchange-exchange" + i + "' name='add-exchange-select-alternate-exchange' value='" + name + "' " + checked + "/></li>");
+ }
+ }
+
+ iTablet.renderList($("#add-exchange-select-alternate-exchange-list"), function(i) {
+ return filteredExchanges[i];
+ }, filteredExchanges.length);
+ };
+
+ var changeType = function(e) {
+ var jthis = $(e.target);
+ if (jthis.attr("checked")) {
+ $("#add-exchange-exchange-type p").text(jthis.siblings("label").text());
+ }
+ };
+
+ this.initialise = function() {
+ $("#add-exchange-additional").unbind("show").bind("show", showAdditionalOptions);
+ $("#add-exchange-select-alternate-exchange").unbind("show").bind("show", showSelectExchange);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#add-exchange .right.button").bind(qmfui.END_EV, submit);
+ $("#exchange-type input").change(changeType);
+
+ // Always initialise to default value irrespective of browser caching.
+ $("#direct").click();
+ };
+}; // End of qmfui.AddExchange definition
+
+
+/**
+ * Create a Singleton instance of the SelectedExchange class managing the id="selected-exchange" page.
+ */
+qmfui.SelectedExchange = new function() {
+ // System Exchanges are exchanges that should not be deleted so we hide the delete button for those Exchanges.
+ var SYSTEM_EXCHANGES = {"''": true, "amq.direct": true, "amq.fanout": true, "amq.match": true, "amq.topic": true,
+ "qmf.default.direct": true, "qmf.default.topic": true, "qpid.management": true};
+
+ // Protected Exchanges are exchanges that we don't binding to - default direct and the QMF exchanges.
+ var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true,
+ "qmf.default.topic": true, "qpid.management": true};
+ var _name = "";
+
+ /**
+ * This method deletes the selected exchange by invoking the QMF delete method.
+ */
+ var deleteHandler = function() {
+ // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice.
+ // Calling confirm within a timeout ensures things are placed correctly onto the event queue.
+ setTimeout(function() {
+ if (confirm('Delete Exchange "' + _name + '"?') == false) {
+ return;
+ } else {
+ var arguments = {"type": "exchange", "name": _name};
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("delete", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+ }, 0);
+ };
+
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#selected-exchange") {
+ return;
+ }
+
+ // Get the latest update of the selected exchange object.
+ var exchangeId = data.id;
+ var exchange = qmfui.Exchanges.getExchange(exchangeId);
+ if (exchange == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ // Populate the page header with the exchange name and type
+ _name = exchange.name;
+ _name = (_name == "") ? "''" : _name;
+ $("#selected-exchange .header h1").text(_name + " (" + exchange.type + ")");
+
+ // If the selected Exchange is a system Exchange hide the delete button, otherwise show it.
+ if (SYSTEM_EXCHANGES[_name]) {
+ $("#selected-exchange .header a.delete").hide();
+ } else {
+ $("#selected-exchange .header a.delete").show();
+ }
+
+ // Populate the back button with "Exchanges" or "Bindings" depending on context
+ var backText = "Exchan...";
+ if (data.bindingKey) {
+ backText = "Bindings";
+ // Ensure that the binding that linked to this page gets correctly highlighted if we navigate back.
+ // If default direct add an extra "&" otherwise all ObjectIds will match in a simple string search.
+ qmfui.Bindings.setHighlightedBinding(exchangeId + (_name == "''" ? "&" : ""),
+ data.bindingKey);
+ }
+
+ // Using $("#selected-exchange .header a").text(backText) wipes all child elements so use the following.
+ $("#selected-exchange .header a")[0].firstChild.nodeValue = backText;
+
+ // Render the bindingCount to #selected-exchange-bindings
+ if (exchange.bindingCount == 0) {
+ // We don't allow bindings to be added to default direct or QMF Exchanges.
+ if (PROTECTED_EXCHANGES[_name]) {
+ iTablet.renderList($("#selected-exchange-bindings"), function(i) {
+ return "<li class='grey'><a href='#'>There are currently no bindings to " + _name + "</a></li>";
+ });
+ } else {
+ iTablet.renderList($("#selected-exchange-bindings"), function(i) {
+ return "<li class='pop'><a href='#add-binding?exchangeId=" + exchangeId + "'>Add Binding</a></li>";
+ });
+ }
+ } else {
+ iTablet.renderList($("#selected-exchange-bindings"), function(i) {
+ return "<li class='arrow'><a href='#bindings?exchangeId=" + exchangeId + "'>bindingCount<p>" +
+ exchange.bindingCount + "</p></a></li>";
+ });
+ }
+
+ // Render the exchange statistics to #selected-exchange-msgio
+ var keys = ["msgReceives", "msgRoutes", "msgDrops"];
+ iTablet.renderList($("#selected-exchange-msgio"), function(i) {
+ var key = keys[i];
+ return "<li class='arrow'><a href='#graphs?exchangeId=" + exchangeId + "&property=" + i + "'>" +
+ key + "<p>" + exchange[key] + "</p></a></li>";
+ }, keys.length);
+
+ // Render the exchange statistics to #selected-exchange-byteio
+ keys = ["byteReceives", "byteRoutes", "byteDrops"];
+ iTablet.renderList($("#selected-exchange-byteio"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + exchange[key] + "</p></a></li>";
+ }, keys.length);
+
+ // Render selected general exchange properties and exchange.declare arguments to #selected-exchange-general.
+ keys = ["durable", "autoDelete", "producerCount"];
+ var general = [];
+
+ // Render any alternate exchange that may be attached to this exchange. Note that exchange.altExchange
+ // is a reference property so we need to dereference it before extracting the exchange name.
+ var altExchange = qmfui.Exchanges.getExchange(exchange.altExchange);
+ if (altExchange) {
+ general.push("<li><a href='#'>altExchange<p>" + altExchange.name + "</p></a></li>");
+ }
+
+ for (var i in keys) { // Populate with selected properties.
+ var key = keys[i];
+ general.push("<li><a href='#'>" + key + "<p>" + exchange[key] + "</p></a></li>");
+ }
+ for (var i in exchange.arguments) { // Populate with arguments.
+ general.push("<li><a href='#'>" + i + "<p>" + exchange.arguments[i] + "</p></a></li>");
+ }
+
+ iTablet.renderList($("#selected-exchange-general"), function(i) {
+ return general[i];
+ }, general.length);
+ }
+ };
+
+ this.initialise = function() {
+ $("#selected-exchange").unbind("show").bind("show", qmfui.SelectedExchange.update);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#selected-exchange .header a.delete").bind(qmfui.END_EV, deleteHandler);
+ };
+}; // End of qmfui.SelectedExchange definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Queue Information
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Queues class managing the id="queues" page.
+ */
+qmfui.Queues = new function() {
+ var QMF_EXCHANGES = { "qmf.default.direct": true, "qmf.default.topic": true, "qpid.management": true};
+ var _queueNameMap = {}; // Queues indexed by name.
+ var _queueMap = {}; // Queues indexed by ObjectId.
+
+ /**
+ * Return the Queue object for the given QMF ObjectId. The Queue object contains the latest update
+ * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period.
+ */
+ this.getQueue = function(oid) {
+ return _queueMap[oid];
+ };
+
+ /**
+ * Return the Queue object with the given name. The Queue object contains the latest update
+ * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period.
+ */
+ this.getQueueByName = function(name) {
+ return _queueNameMap[name];
+ };
+
+ this.update = function() {
+ var hideQmfObjects = $("#settings-hide-qmf-objects")[0].checked;
+
+ // We move active queues to temp so deleted queues wither and die. We can't just do _queueMap = {} as we
+ // need to retrieve and update statistics from any active (non-deleted) queue.
+ var temp = {};
+ _queueNameMap = {}; // We can simply clear the map of queues indexed by name though.
+ var queues = qmfui.Console.getQueues();
+ iTablet.renderList($("#queues-list"), function(i) {
+ var queue = queues[i];
+ var objectId = queue._object_id;
+
+ // Look up the previous value for the indexed queue using its objectId.
+ var prev = _queueMap[objectId];
+ var stats = (prev == null) ? new qmfui.Statistics(["msgDepth", "msgTotalEnqueues", "msgTotalDequeues"]) :
+ prev._statistics;
+
+ stats.put([queue.msgDepth, queue.msgTotalEnqueues, queue.msgTotalDequeues, queue._update_ts]);
+
+ // Add statistics as an additional property of the queue object.
+ queue._statistics = stats;
+
+ /*
+ * Check if the queue is associated with a QMF exchange. Because we need to iterate through the
+ * bindings in an inner loop we only want to do this once for each queue, however we can't only
+ * do it when the queue is missing from the _queueMap, because there's a race condition with QMF
+ * properties getting asynchronously returned, so it's possible for a queue to exist without a
+ * binding object referencing it existing for a short period, so we don't add the _isQmfQueue
+ * property until a binding referencing the queue actually exists.
+ */
+ if (prev == null || prev._isQmfQueue == null) {
+ var bindings = qmfui.Console.getBindings(); // Get the cached list of binding objects.
+ for (var i in bindings) {
+ var b = bindings[i];
+ if (b.queueRef == objectId) {
+ var exchange = qmfui.Exchanges.getExchange(b.exchangeRef); // Dereference the exchangeRef.
+ if (exchange != null) {
+ // If a binding referencing the queue and an exchange exists add isQmfQueue state as an
+ // additional property of the queue object.
+ if (QMF_EXCHANGES[exchange.name]) {
+ queue._isQmfQueue = true;
+ break;
+ } else {
+ queue._isQmfQueue = false;
+ }
+ }
+ }
+ }
+ } else {
+ // Add previous status of _isQmfQueue as an additional property of the queue object.
+ queue._isQmfQueue = prev._isQmfQueue;
+ }
+
+ temp[objectId] = queue;
+ _queueNameMap[queue.name] = queue;
+
+ if (queue._isQmfQueue && hideQmfObjects) {
+ return false; // Filter out any QMF related queues if the settings filter is checked.
+ } else {
+ return "<li class='arrow'><a href='#selected-queue?id=" + objectId + "'>" + queue.name + "</a></li>";
+ }
+ }, queues.length);
+
+ // Replace the saved statistics with the newly populated temp instance, which only has active objects
+ // moved to it, this means that any deleted objects are no longer present.
+ _queueMap = temp;
+ };
+
+}; // End of qmfui.Queues definition
+
+
+/**
+ * Create a Singleton instance of the AddQueue class managing the id="add-queue" page.
+ */
+qmfui.AddQueue = new function() {
+ // Protected Exchanges are exchanges that we don't permit binding to - default direct and the QMF exchanges.
+ var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true,
+ "qmf.default.topic": true, "qpid.management": true};
+ var _properties = {};
+ var _alternateExchangeName = "None (default)";
+
+ var parseIntegerProperty = function(selector, name) {
+ var value = $(selector).removeClass("error").val();
+ if (value == "") {
+ return true; // "" doesn't populate the property, but it's still valid so return true;
+ } else {
+ if (value.search(/[kKmMgG]/) == (value.length - 1)) { // Does it end in K/M/G
+ _properties[name] = value;
+ return true;
+ } else {
+ var integer = parseInt(value);
+ if (isNaN(integer)) {
+ $(selector).addClass("error");
+ return false;
+ } else {
+ _properties[name] = integer;
+ return true;
+ }
+ }
+ }
+ };
+
+ var submit = function() {
+ _properties = {};
+
+ if (!parseIntegerProperty("#max-queue-size", "qpid.max_size")) {
+ return;
+ } else if (!parseIntegerProperty("#max-queue-count", "qpid.max_count")) {
+ return;
+ } else if (!parseIntegerProperty("#flow-stop-size", "qpid.flow_stop_size")) {
+ return;
+ } else if (!parseIntegerProperty("#flow-stop-count", "qpid.flow_stop_count")) {
+ return;
+ } else if (!parseIntegerProperty("#flow-resume-size", "qpid.flow_resume_size")) {
+ return;
+ } else if (!parseIntegerProperty("#flow-resume-count", "qpid.flow_resume_count")) {
+ return;
+ }
+
+ if ($("#queue-durable")[0].checked) {
+ _properties["durable"] = true;
+ if (!parseIntegerProperty("#file-size", "qpid.file_size")) {
+ return;
+ } else if (!parseIntegerProperty("#file-count", "qpid.file_count")) {
+ return;
+ }
+
+ if ($("#queue-cluster-durable")[0].checked) {
+ _properties["qpid.persist_last_node"] = 1;
+ }
+ } else {
+ _properties["durable"] = false;
+ }
+
+ var limitPolicy = $("#limit-policy input[checked]").val();
+ if (limitPolicy != "none") {
+ _properties["qpid.policy_type"] = limitPolicy;
+ }
+
+ var orderingPolicy = $("#ordering-policy input[checked]").val();
+ if (orderingPolicy == "lvq") {
+ _properties["qpid.last_value_queue"] = 1;
+ } else if (orderingPolicy == "lvq-no-browse") {
+ _properties["qpid.last_value_queue_no_browse"] = 1;
+ }
+
+ if (!parseIntegerProperty("#generate-queue-events input[checked]", "qpid.queue_event_generation")) {
+ return;
+ }
+
+ if (_alternateExchangeName != "None (default)") {
+ _properties["alternate-exchange"] = _alternateExchangeName;
+ }
+
+ var queueName = $("#queue-name");
+ var name = queueName.val();
+ if (name == "") {
+ queueName.addClass("error");
+ } else {
+ queueName.removeClass("error");
+
+ var arguments = {"type": "queue", "name": name, "properties": _properties};
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("create", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+ };
+
+ /**
+ * This method renders dynamic content in the AdditionalOptions page, it's really there to make sure that
+ * the AlternateExchange name gets properly rendered when it gets selected in the
+ * "#add-exchange-select-alternate-exchange" page.
+ */
+ var showAdditionalOptions = function() {
+ _alternateExchangeName = $("#add-queue-select-alternate-exchange-list input[checked]").val();
+ var exchange = qmfui.Exchanges.getExchangeByName(_alternateExchangeName);
+ var exchangeType = (exchange == null) ? "" : exchange.type;
+ var typeText = (exchangeType == "") ? "" : " (" + exchangeType + ")";
+ $("#add-queue-additional-alternate-exchange-name p").text(_alternateExchangeName + typeText);
+ };
+
+ /**
+ * This method renders the reroute-messages-select-exchange page when its show event is triggered. This page
+ * needs a show handler because it needs to be dynamically updated as the exchanges available in the radio
+ * button selection set will vary as exchanges get added or deleted.
+ */
+ var showSelectExchange = function() {
+ var exchanges = qmfui.Console.getExchanges();
+ var filteredExchanges = [];
+ var currentlySelected = $("#add-queue-additional-alternate-exchange-name p").text();
+
+ // Check the status of any Exchange that the user may have previously selected prior to hitting "Done".
+ if (currentlySelected != "None (default)") {
+ // Remove the exchange type from the text before testing.
+ currentlySelected = currentlySelected.split(" (")[0];
+ if (qmfui.Exchanges.getExchangeByName(currentlySelected) == null) { // Check if it has been deleted.
+ alert('The currently selected Exchange "' + currentlySelected + '" appears to have been deleted.');
+ currentlySelected = "None (default)";
+ }
+ }
+
+ var checked = (currentlySelected == "None (default)") ? "checked" : "";
+ filteredExchanges.push("<li><label for='add-queue-select-alternate-exchange-exchangeNone'>None (default)</label><input type='radio' id='add-queue-select-alternate-exchange-exchangeNone' name='add-queue-select-alternate-exchange' value='None (default)' " + checked + "/></li>");
+
+ var length = exchanges.length;
+ for (var i = 0; i < length; i++) {
+ var name = exchanges[i].name;
+ var type = exchanges[i].type;
+ checked = (currentlySelected == name) ? "checked" : "";
+
+ // Filter out default direct and QMF exchanges as we don't want to allow binding to those.
+ if (!PROTECTED_EXCHANGES[name]) {
+ filteredExchanges.push("<li><label for='add-queue-select-alternate-exchange-exchange" + i + "'>" + name + " (" + type + ")</label><input type='radio' id='add-queue-select-alternate-exchange-exchange" + i + "' name='add-queue-select-alternate-exchange' value='" + name + "' " + checked + "/></li>");
+ }
+ }
+
+ iTablet.renderList($("#add-queue-select-alternate-exchange-list"), function(i) {
+ return filteredExchanges[i];
+ }, filteredExchanges.length);
+ };
+
+ var changeLimitPolicy = function(e) {
+ var jthis = $(e.target);
+ if (jthis.attr("checked")) {
+ $("#add-queue-limit-policy p").text(jthis.siblings("label").text());
+ }
+ };
+
+ var changeOrderingPolicy = function(e) {
+ var jthis = $(e.target);
+ if (jthis.attr("checked")) {
+ var value = jthis.attr("value");
+ if (value == "fifo") {
+ $("#add-queue-ordering-policy p").text("Fifo (default)");
+ } else if (value == "lvq") {
+ $("#add-queue-ordering-policy p").text("LVQ");
+ } else if (value == "lvq-no-browse") {
+ $("#add-queue-ordering-policy p").text("LVQ No Browse");
+ }
+ }
+ };
+
+ var changeQueueEventGeneration = function(e) {
+ var jthis = $(e.target);
+ if (jthis.attr("checked")) {
+ $("#add-queue-generate-queue-events p").text(jthis.siblings("label").text());
+ }
+ };
+
+ var changeDurable = function(e) {
+ var durable = $("#queue-durable")[0].checked;
+ var durableList = $("#add-queue-additional-durable-list");
+ var hiddenList = $("#add-queue-additional-hidden-list").hide();
+
+ if (durable) {
+ setTimeout(function() {
+ $("#queue-cluster-durable").parent().appendTo(durableList);
+ iTablet.renderList(durableList);
+ setTimeout(function() {
+ $("#file-size").parent().appendTo(durableList);
+ iTablet.renderList(durableList);
+ setTimeout(function() {
+ $("#file-count").parent().appendTo(durableList);
+ iTablet.renderList(durableList);
+ $("#add-queue-additional").trigger("refresh"); // Refresh touch scroller.
+ }, 30);
+ }, 30);
+ }, 30);
+
+ $("#add-queue-additional-journal-note").show();
+ } else {
+ if ($("#queue-cluster-durable").is(":checked")) {
+ // Have to use a timeout to call click() within an event handler.
+ setTimeout(function() {$("#queue-cluster-durable").click();}, 0);
+ }
+
+ setTimeout(function() {
+ $("#file-count").parent().appendTo(hiddenList);
+ setTimeout(function() {
+ $("#file-size").parent().appendTo(hiddenList);
+ setTimeout(function() {
+ $("#queue-cluster-durable").parent().appendTo(hiddenList);
+ iTablet.renderList(durableList);
+ $("#add-queue-additional").trigger("refresh"); // Refresh touch scroller.
+ }, 30);
+ }, 30);
+ }, 30);
+
+ $("#add-queue-additional-journal-note").hide();
+ }
+ };
+
+ this.initialise = function() {
+ $("#add-queue-additional").unbind("show").bind("show", showAdditionalOptions);
+ $("#add-queue-select-alternate-exchange").unbind("show").bind("show", showSelectExchange);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#add-queue .right.button").bind(qmfui.END_EV, submit);
+ $("#limit-policy input").change(changeLimitPolicy);
+ $("#ordering-policy input").change(changeOrderingPolicy);
+ $("#generate-queue-events input").change(changeQueueEventGeneration);
+
+ // Always initialise to default value irrespective of browser caching.
+ $("#none").click();
+ $("#fifo").click();
+ $("#generate-no-events").click();
+
+ changeDurable();
+ $("#queue-durable").change(changeDurable);
+ };
+}; // End of qmfui.AddQueue definition
+
+
+/**
+ * Create a Singleton instance of the SelectedQueue class managing the id="selected-queue" page.
+ */
+qmfui.SelectedQueue = new function() {
+ var _name = "";
+
+ // The Queue depth and number of consumers are reported during the Queue delete confirmation process.
+ var _depth = 0;
+ var _consumers = 0;
+
+ /**
+ * This method deletes the selected queue by invoking the QMF delete method.
+ */
+ var deleteHandler = function() {
+ var plural = (_consumers == 1) ? " consumer?" : " consumers?"
+
+ // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice.
+ // Calling confirm within a timeout ensures things are placed correctly onto the event queue.
+ setTimeout(function() {
+ if (confirm('Delete Queue "' + _name +
+ '"\nwhich contains ' + _depth + " messages and has " + _consumers + plural) == false) {
+ return;
+ } else {
+ var arguments = {"type": "queue", "name": _name};
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("delete", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+ }, 0);
+ };
+
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#selected-queue") {
+ return;
+ }
+
+ // Get the latest update of the selected queue object.
+ var queueId = data.id;
+ var queue = qmfui.Queues.getQueue(queueId);
+ if (queue == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ _name = queue.name;
+ _depth = queue.msgDepth; // Reported to user if Queue delete is selected.
+ _consumers = queue.consumerCount; // Reported to user if Queue delete is selected.
+
+ // Populate the page header with the queue name.
+ $("#selected-queue .header h1").text(_name);
+
+ // If the selected Queue is a QMF Queue hide the delete button, otherwise show it.
+ // Deleting QMF Queues is a bad thing as it will stop any QMF Consoles behaving as the should.
+ if (queue._isQmfQueue) {
+ $("#selected-queue .header a.delete").hide();
+ $("#selected-queue-admin-wrapper").hide();
+ } else {
+ $("#selected-queue .header a.delete").show();
+ $("#selected-queue-admin-wrapper").show();
+ }
+
+ // Populate the back button with "Queues", "Bindings" or "Subscriptions" depending on context
+ var backText = "Queues";
+ if (data.bindingKey) {
+ backText = "Bindings";
+ // Ensure that the binding that linked to this page gets correctly highlighted if we navigate back.
+ qmfui.Bindings.setHighlightedBinding(queueId, data.bindingKey);
+ } else if (data.fromSubscriptions) {
+ backText = "Subscrip...";
+ }
+
+ // Using $("#selected-queue .header a").text(backText) wipes all child elements so use the following.
+ $("#selected-queue .header a")[0].firstChild.nodeValue = backText;
+
+ // Render the bindingCount to #selected-queue-bindings
+ // There should always be at least one binding to a queue as the default direct exchange is always bound.
+ iTablet.renderList($("#selected-queue-bindings"), function(i) {
+ return "<li class='arrow'><a href='#bindings?queueId=" + queueId + "'>bindingCount<p>" +
+ queue.bindingCount + "</p></a></li>";
+ });
+
+ // Render the queue statistics to #selected-queue-msgio
+ var keys = ["msgDepth", "msgTotalEnqueues", "msgTotalDequeues"];
+ iTablet.renderList($("#selected-queue-msgio"), function(i) {
+ var key = keys[i];
+ return "<li class='arrow'><a href='#graphs?queueId=" + queueId + "&property=" + i + "'>" + key +
+ "<p>" + queue[key] + "</p></a></li>";
+ }, keys.length);
+
+ // Render the queue statistics to #selected-queue-byteio
+ keys = ["byteDepth", "byteTotalEnqueues", "byteTotalDequeues"];
+ iTablet.renderList($("#selected-queue-byteio"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + queue[key] + "</p></a></li>";
+ }, keys.length);
+
+ // Render selected general queue properties and queue.declare arguments to #selected-queue-general.
+ keys = ["durable", "autoDelete", "exclusive", "unackedMessages", "acquires", "releases",
+ "messageLatency", "messageLatencyAvg", "consumerCount", "flowStopped", "flowStoppedCount"];
+ var general = [];
+
+ // Render any alternate exchange that may be attached to this queue. Note that queue.altExchange
+ // is a reference property so we need to dereference it before extracting the exchange name.
+ var altExchange = qmfui.Exchanges.getExchange(queue.altExchange);
+ if (altExchange) {
+ general.push("<li><a href='#'>altExchange<p>" + altExchange.name + "</p></a></li>");
+ }
+
+ for (var i in keys) { // Populate with selected properties.
+ var key = keys[i];
+ var value = queue[key];
+ if (value != null) {
+ general.push("<li><a href='#'>" + key + "<p>" + value + "</p></a></li>");
+ }
+ }
+ for (var i in queue.arguments) { // Populate with arguments.
+ general.push("<li><a href='#'>" + i + "<p>" + queue.arguments[i] + "</p></a></li>");
+ }
+
+ iTablet.renderList($("#selected-queue-general"), function(i) {
+ return general[i];
+ }, general.length);
+
+ var hideDetails = $("#settings-hide-details")[0].checked;
+
+ // Render the Flow-to-disk Statistics.
+ if (queue.msgFtdDepth == null || hideDetails) {
+ $("#selected-queue-flow-to-disk-container").hide();
+ } else {
+ $("#selected-queue-flow-to-disk-container").show();
+ keys = ["msgFtdDepth", "msgFtdEnqueues", "msgFtdDequeues",
+ "byteFtdDepth", "byteFtdEnqueues", "byteFtdDequeues"];
+ iTablet.renderList($("#selected-queue-flow-to-disk"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + queue[key] + "</p></a></li>";
+ }, keys.length);
+ }
+
+ // Render the Dequeue Details.
+ if (queue.discardsTtl == null || hideDetails) {
+ $("#selected-queue-dequeue-container").hide();
+ } else {
+ $("#selected-queue-dequeue-container").show();
+ keys = ["discardsTtl", "discardsRing", "discardsLvq", "discardsOverflow",
+ "discardsSubscriber", "discardsPurge", "reroutes"];
+ iTablet.renderList($("#selected-queue-dequeue"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + queue[key] + "</p></a></li>";
+ }, keys.length);
+ }
+
+ // Render links to the subscriptions associated with this queue to #selected-queue-subscriptions.
+ // Unfortunately the subscription name isn't especially useful so find the associated connection
+ // and display the connection address instead.
+ var subscriptions = qmfui.Connections.getQueueSubscriptions(queueId);
+ if (subscriptions.length == 0) {
+ iTablet.renderList($("#selected-queue-subscriptions"), function(i) {
+ return "<li class='grey'><a href='#'>There are currently no subscriptions to " + _name + "</a></li>";
+ });
+ } else {
+ iTablet.renderList($("#selected-queue-subscriptions"), function(i) {
+ var subscription = subscriptions[i];
+ var id = subscription._object_id;
+
+ // The subscription.sessionRef really should be present, but the Java Broker does not yet correctly
+ // populate the association between Subscription and Session so we need this defensive block.
+ if (subscription.sessionRef != null) {
+ var session = qmfui.Connections.getSession(subscription.sessionRef);
+ var connection = qmfui.Connections.getConnection(session.connectionRef);
+ var address = connection.address + " (" + connection.remoteProcessName + ")";
+ return "<li class='arrow'><a href='#queue-subscriptions?id=" + id + "'>" + address + "</a></li>";
+ } else {
+ return "<li class='arrow'><a href='#queue-subscriptions?id=" + id + "'>" + subscription.name + "</a></li>";
+ }
+ }, subscriptions.length);
+ }
+
+ // We have to dynamically render the admin list so that we can attach the queueId to the URL.
+ var admin = [];
+ admin.push("<li class='arrow pop'><a href='#purge-queue?queueId=" + queueId + "'>Purge</a></li>");
+ admin.push("<li class='arrow pop'><a href='#reroute-messages?queueId=" + queueId + "'>Reroute Messages</a></li>");
+ admin.push("<li class='arrow pop'><a href='#move-messages?queueId=" + queueId + "'>Move Messages</a></li>");
+
+ iTablet.renderList($("#selected-queue-admin"), function(i) {
+ return admin[i];
+ }, admin.length);
+
+ }
+ };
+
+ this.initialise = function() {
+ $("#selected-queue").unbind("show").bind("show", qmfui.SelectedQueue.update);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#selected-queue .header a.delete").bind(qmfui.END_EV, deleteHandler);
+ };
+}; // End of qmfui.SelectedQueue definition
+
+
+/**
+ * Create a Singleton instance of the QueueSubscriptions class managing the id="queue-subscriptions" page.
+ */
+qmfui.QueueSubscriptions = new function() {
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#queue-subscriptions") {
+ return;
+ }
+
+ var subscriptionId = data.id;
+ var subscription = qmfui.Connections.getSubscription(subscriptionId);
+ if (subscription == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ var session = qmfui.Connections.getSession(subscription.sessionRef);
+ session = session ? session : {};
+ var connection = qmfui.Connections.getConnection(session.connectionRef);
+ connection = connection ? connection : {};
+
+ // The connection.address should be present but for the 0.20 Java Broker it is not yet populated
+ // so we need to do some defensive code to check if it's set and if not render subscription.name.
+ var name = connection.address ? connection.address + " (" + connection.remoteProcessName + ")" :
+ subscription.name;
+
+ var connectionId = connection._object_id;
+
+ // Populate the page header with the address of the connection associated with the subscription.
+ $("#queue-subscriptions .header h1").text(name);
+
+ iTablet.renderList($("#queue-subscriptions-connection"), function(i) {
+ if (connectionId) {
+ return "<li class='arrow'><a href='#selected-connection?id=" + connectionId +
+ "&fromSubscription=true'>" + name + "</a></li>";
+ } else {
+ return "<li><a href='#'>Connection is Unknown</a></li>";
+ }
+ });
+
+ // subscription.sessionRef should be present but for the 0.20 Java Broker it is not yet populated
+ // so we need to do some defensive code to check if it's set and if not render "Session is Unknown".
+ if (subscription.sessionRef) {
+ // Render the useful session properties to #queue-subscriptions-session
+ var keys = ["name", "framesOutstanding", "unackedMessages", "channelId",
+ "maxClientRate", "clientCredit"];
+ iTablet.renderList($("#queue-subscriptions-session"), function(i) {
+ var key = keys[i];
+ var value = session[key];
+ if (value == null) {
+ return false;
+ } else {
+ return "<li><a href='#'>" + key + "<p>" + value + "</p></a></li>";
+ }
+ }, keys.length);
+ } else {
+ iTablet.renderList($("#queue-subscriptions-session"), function(i) {
+ return "<li><a href='#'>Session is Unknown</a></li>";
+ });
+ }
+
+ // Render the useful subscription properties to #queue-subscriptions-subscription
+ keys = ["name", "delivered", "browsing", "acknowledged", "exclusive", "creditMode"];
+ iTablet.renderList($("#queue-subscriptions-subscription"), function(i) {
+ var key = keys[i];
+ return "<li><a href='#'>" + key + "<p>" + subscription[key] + "</p></a></li>";
+ }, keys.length);
+ }
+ };
+
+ this.initialise = function() {
+ $("#queue-subscriptions").unbind("show").bind("show", qmfui.QueueSubscriptions.update);
+ };
+}; // End of qmfui.QueueSubscriptions definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Queue Admin
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the PurgeQueue class managing the id="purge-queue" page.
+ */
+qmfui.PurgeQueue = new function() {
+ /**
+ * Actually purge the messages using the QMF purge method on the Queue Management Object.
+ */
+ var submit = function() {
+ var location = iTablet.location;
+ var data = location.data;
+
+ if (data == null || location.hash != "#purge-queue") {
+ return;
+ }
+
+ var selector = $("#purge-queue-request-number");
+ var value = selector.val();
+ var messageCount = 0;
+ if (value != "") {
+ messageCount = parseInt(value);
+ if (isNaN(messageCount)) {
+ selector.addClass("error");
+ return false;
+ }
+ }
+
+ selector.removeClass("error");
+
+ var queueId = data.queueId;
+ var queue = qmfui.Queues.getQueue(queueId);
+ qmfui.Console.makeConsoleData(queue); // Make queue a QmfConsoleData object with an invokeMethod method.
+
+ // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice.
+ // Calling confirm within a timeout ensures things are placed correctly onto the event queue.
+ var countText = (messageCount == 0) ? "all" : messageCount;
+ setTimeout(function() {
+ if (confirm('Purge ' + countText + ' messages from "' + queue.name + '"?') == false) {
+ return;
+ } else {
+ var arguments = {"request": messageCount};
+
+ queue.invokeMethod("purge", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+ }, 0);
+ };
+
+ this.initialise = function() {
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#purge-queue .right.button").bind(qmfui.END_EV, submit);
+ };
+}; // End of qmfui.PurgeQueue definition
+
+
+/**
+ * Create a Singleton instance of the RerouteMessages class managing the id="reroute-messages" page.
+ */
+qmfui.RerouteMessages = new function() {
+ // Protected Exchanges are exchanges that we don't permit binding to - default direct and the QMF exchanges.
+ var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true,
+ "qmf.default.topic": true, "qpid.management": true};
+ var _exchangeName = "";
+
+ /**
+ * Actually reroute the messages using the QMF reroute method on the Queue Management Object.
+ */
+ var submit = function() {
+ var location = iTablet.location;
+ var data = location.data;
+
+ if (data == null || location.hash != "#reroute-messages") {
+ return;
+ }
+
+ var selector = $("#reroute-messages-request-number");
+ var value = selector.val();
+ var messageCount = 0;
+ if (value != "") {
+ messageCount = parseInt(value);
+ if (isNaN(messageCount)) {
+ selector.addClass("error");
+ return false;
+ }
+ }
+
+ selector.removeClass("error");
+
+ var queueId = data.queueId;
+ var queue = qmfui.Queues.getQueue(queueId);
+ qmfui.Console.makeConsoleData(queue); // Make queue a QmfConsoleData object with an invokeMethod method.
+
+ var useAltExchange = $("#reroute-messages-use-alternate-exchange")[0].checked;
+
+ // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice.
+ // Calling confirm within a timeout ensures things are placed correctly onto the event queue.
+ var countText = (messageCount == 0) ? "all" : messageCount;
+ var exchangeText = useAltExchange ? "Alternate Exchange?" : _exchangeName + "?";
+ setTimeout(function() {
+ if (confirm('Reroute ' + countText + ' messages from "' + queue.name + '" to ' + exchangeText) == false) {
+ return;
+ } else {
+ var arguments = {"request": messageCount, "useAltExchange": useAltExchange};
+ if (!useAltExchange) {
+ arguments["exchange"] = _exchangeName;
+ }
+
+ queue.invokeMethod("reroute", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+ }, 0);
+ };
+
+ /**
+ * This method renders the main reroute-messages page when it is made visible by the show event being triggered.
+ * It's mainly just getting the state of the reroute-messages-select-exchange-list and that could have been
+ * set by binding a change handler to that, but as reroute-messages-select-exchange-list is dynamically
+ * constructed that involves rebinding every time it's shown. Getting the state in the show handler here
+ * also ensures that the _exchangeName is always set to something.
+ */
+ var show = function() {
+ if ($("#reroute-messages-use-alternate-exchange")[0].checked) {
+ $("#reroute-messages-use-selected-exchange").hide();
+ } else {
+ $("#reroute-messages-use-selected-exchange").show();
+ _exchangeName = $("#reroute-messages-select-exchange-list input[checked]").val();
+ var exchange = qmfui.Exchanges.getExchangeByName(_exchangeName);
+ var exchangeType = (exchange == null) ? "" : exchange.type;
+ var typeText = (exchangeType == "") ? "" : " (" + exchangeType + ")";
+ $("#reroute-messages-exchange-name p").text(_exchangeName + typeText);
+ }
+ };
+
+ /**
+ * This method renders the reroute-messages-select-exchange page when its show event is triggered. This page
+ * needs a show handler because it needs to be dynamically updated as the exchanges available in the radio
+ * button selection set will vary as exchanges get added or deleted.
+ */
+ var showSelectExchange = function() {
+ var exchanges = qmfui.Console.getExchanges();
+ var filteredExchanges = [];
+ var currentlySelected = $("#reroute-messages-exchange-name p").text();
+
+ // Check the status of any Exchange that the user may have previously selected prior to hitting "Done".
+ if (currentlySelected != "None (default)") {
+ // Remove the exchange type from the text before testing.
+ currentlySelected = currentlySelected.split(" (")[0];
+ if (qmfui.Exchanges.getExchangeByName(currentlySelected) == null) { // Check if it has been deleted.
+ alert('The currently selected Exchange "' + currentlySelected + '" appears to have been deleted.');
+ currentlySelected = "None (default)";
+ }
+ }
+
+ var checked = (currentlySelected == "None (default)") ? "checked" : "";
+ filteredExchanges.push("<li><label for='reroute-messages-exchangeNone'>None (default)</label><input type='radio' id='reroute-messages-exchangeNone' name='reroute-messages-select-exchange' value='None (default)' " + checked + "/></li>");
+
+ var length = exchanges.length;
+ for (var i = 0; i < length; i++) {
+ var name = exchanges[i].name;
+ var type = exchanges[i].type;
+ checked = (currentlySelected == name) ? "checked" : "";
+
+ // Filter out default direct and QMF exchanges as we don't want to allow binding to those.
+ if (!PROTECTED_EXCHANGES[name]) {
+ filteredExchanges.push("<li><label for='reroute-messages-exchange" + i + "'>" + name + " (" + type + ")</label><input type='radio' id='reroute-messages-exchange" + i + "' name='reroute-messages-select-exchange' value='" + name + "' " + checked + "/></li>");
+ }
+ }
+
+ iTablet.renderList($("#reroute-messages-select-exchange-list"), function(i) {
+ return filteredExchanges[i];
+ }, filteredExchanges.length);
+ };
+
+ this.initialise = function() {
+ $("#reroute-messages").unbind("show").bind("show", show);
+ $("#reroute-messages-select-exchange").unbind("show").bind("show", showSelectExchange);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#reroute-messages .right.button").bind(qmfui.END_EV, submit);
+ $("#reroute-messages-use-alternate-exchange").change(show);
+ };
+}; // End of qmfui.RerouteMessages definition
+
+
+/**
+ * Create a Singleton instance of the RerouteMessages class managing the id="move-messages" page.
+ */
+qmfui.MoveMessages = new function() {
+ var _sourceQueueName = ""; // Get this in the show() method so we can filter it out in showSelectQueue()
+ var _destinationQueueName = "";
+ var _sourceQueue = {};
+
+ /**
+ * Actually reroute the messages using the QMF reroute method on the Queue Management Object.
+ */
+ var submit = function() {
+ // The queueMoveMessages method returns an InvalidParameter Exception if called when srcQueue has msgDepth == 0
+ // This is pretty confusing as the parameters *are* actually OK. https://issues.apache.org/jira/browse/QPID-4543
+ // has been raised on this but the following is some defensive logic to provide a more helpful warning.
+ if (_sourceQueue.msgDepth == 0) {
+ setTimeout(function() {
+ alert("Can't call Move Messages on a queue with a msgDepth of zero");
+ return false;
+ }, 0);
+ } else {
+ var selector = $("#move-messages-request-number");
+ var value = selector.val();
+ var messageCount = 0;
+ if (value != "") {
+ messageCount = parseInt(value);
+ if (isNaN(messageCount)) {
+ selector.addClass("error");
+ return false;
+ }
+ }
+
+ selector.removeClass("error");
+
+ // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice.
+ // Calling confirm within a timeout ensures things are placed correctly onto the event queue.
+ var countText = (messageCount == 0) ? "all" : messageCount;
+ setTimeout(function() {
+ if (confirm('Move ' + countText + ' messages from "' + _sourceQueueName + '" to "' + _destinationQueueName + '"?') == false) {
+ return;
+ } else {
+ var arguments = {"srcQueue": _sourceQueueName, "destQueue": _destinationQueueName, "qty": messageCount};
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("queueMoveMessages", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+ }, 0);
+ }
+ };
+
+ /**
+ * This method renders the main move-messages page when it is made visible by the show event being triggered.
+ * It's mainly just getting the state of the move-messages-select-queue-list and that could have been
+ * set by binding a change handler to that, but as move-messages-select-queue-list is dynamically
+ * constructed that involves rebinding every time it's shown. Getting the state in the show handler here
+ * also ensures that the _destinationQueueName is always set to something.
+ */
+ var show = function() {
+ var location = iTablet.location;
+ var data = location.data;
+
+ if (data == null || location.hash != "#move-messages") {
+ return;
+ }
+
+ var queueId = data.queueId;
+ _sourceQueue = qmfui.Queues.getQueue(queueId);
+ _sourceQueueName = (_sourceQueue == null) ? "" : _sourceQueue.name
+ _destinationQueueName = $("#move-messages-select-queue-list input[checked]").val();
+
+ if (_sourceQueueName == _destinationQueueName) {
+ $("#move-messages-queue-name p").text("None (default)");
+ } else {
+ $("#move-messages-queue-name p").text(_destinationQueueName);
+ }
+ };
+
+ /**
+ * This method renders the add-binding-select-queue page when its show event is triggered. This page
+ * needs a show handler because it needs to be dynamically updated as the queues available in the radio
+ * button selection set will vary as queues get added or deleted.
+ */
+ var showSelectQueue = function() {
+ var queues = qmfui.Console.getQueues();
+ var filteredQueues = [];
+ var currentlySelected = $("#move-messages-queue-name p").text();
+
+ // Check the status of any Queue that the user may have previously selected prior to hitting "Done".
+ if (currentlySelected != "None (default)") {
+ if (qmfui.Queues.getQueueByName(currentlySelected) == null) { // Check if it has been deleted.
+ alert('The currently selected Queue "' + currentlySelected + '" appears to have been deleted.');
+ currentlySelected = "None (default)";
+ }
+ }
+
+ var checked = (currentlySelected == "None (default)") ? "checked" : "";
+ filteredQueues.push("<li><label for='move-messages-select-queueNone'>None (default)</label><input type='radio' id='move-messages-select-queueNone' name='move-messages-select-queue' value='None (default)' " + checked + "/></li>");
+
+ var length = queues.length;
+ for (var i = 0; i < length; i++) {
+ var name = queues[i].name;
+ // We do getQueueByName(name) because the _isQmfQueue property is a "fake" property added by the
+ // qmfui.Queues class, it's only stored in QMF objects held in the getQueueByName() and getQueue() caches.
+ var isQmfQueue = qmfui.Queues.getQueueByName(name)._isQmfQueue;
+ checked = (currentlySelected == name) ? "checked" : "";
+
+ // Filter out queues bound to QMF exchanges as we don't want to allow additional binding to those.
+ // We also filter out the sourceQueueName as there's no point moving messages to self.
+ if (!isQmfQueue && (name != _sourceQueueName)) {
+ filteredQueues.push("<li><label for='move-messages-select-queue" + i + "'>" + name + "</label><input type='radio' id='move-messages-select-queue" + i + "' name='move-messages-select-queue' value='" + name + "' " + checked + "/></li>");
+ }
+ }
+
+ iTablet.renderList($("#move-messages-select-queue-list"), function(i) {
+ return filteredQueues[i];
+ }, filteredQueues.length);
+ };
+
+ this.initialise = function() {
+ $("#move-messages").unbind("show").bind("show", show);
+ $("#move-messages-select-queue").unbind("show").bind("show", showSelectQueue);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#move-messages .right.button").bind(qmfui.END_EV, submit);
+ };
+}; // End of qmfui.MoveMessages definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Generic Bindings Rendering Page
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Bindings class managing the id="bindings" page.
+ */
+qmfui.Bindings = new function() {
+ // Protected Exchanges are exchanges that we don't permit unbinding from - default direct and the QMF exchanges.
+ var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true,
+ "qmf.default.topic": true, "qpid.management": true};
+ var _highlightedObject = null;
+ var _highlightedObjectKey = null;
+
+ /**
+ * This method is used to render the binding information for headers and XML exchanges which need a little
+ * bit more effort than just rendering the binding key. We use <p class="title"> and <p class="sub">
+ * to give fairly neat formatting.
+ *
+ * @param exchange the exchange that the binding is bound to.
+ * @param binding the binding that we wish to render.
+ */
+ var render = function(exchange, binding) {
+ if (exchange.type == "headers") {
+ var arguments = binding.arguments;
+ var headers = "<p class='title'>x-match: " + arguments["x-match"] + "</p>";
+ for (var key in arguments) {
+ if (key != "x-match") {
+ headers = headers + "<p class='sub'>" + key + ": " + arguments[key] + "</p>";
+ }
+ }
+ return headers;
+ } else if (exchange.type == "xml") {
+ var arguments = binding.arguments;
+ var xquery = "<p class='title'>xquery:</p>";
+ xquery = xquery + "<p class='sub'>" + arguments["xquery"] + "</p>";
+ return xquery;
+ } else {
+ return "&nbsp;";
+ }
+ };
+
+ /**
+ * This method confirms the unbind request and invokes the QMF delete binding method on the broker.
+ *
+ * @param exchangeName the exchange that we wish to unbind from.
+ * @param queueName the queue that we wish to unbind from.
+ * @param bindingKey the binding key that we wish to unbind from.
+ */
+ var unbind = function(exchangeName, queueName, bindingKey) {
+ var bindingIdentifier = exchangeName + "/" + queueName;
+ if (bindingKey != "") {
+ bindingIdentifier = bindingIdentifier + "/" + bindingKey;
+ }
+
+ if (confirm('Delete Binding "' + bindingIdentifier + '"?') == false) {
+ return;
+ } else {
+ var arguments = {"type": "binding", "name": bindingIdentifier};
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("delete", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ }
+ });
+ }
+ };
+
+ /**
+ * This handler is triggered by clicking a <li class="clickable-icon">. Unfortunately there's bit more work
+ * to do because we only want to respond if the actual icon has been clicked so we need to work out the
+ * mouse or tap position within the li and check it's less than the icon width.
+ * Once we're happy that we've clicked the icon we need to work out which binding the <li> relates to. The
+ * approach to this is a little messy and involves scraping some of the html associated with the <li>
+ */
+ var clickHandler = function(e) {
+ var target = e.target;
+ var jthis = $(target).closest("ul li.clickable-icon");
+
+ if (jthis.length != 0) {
+ var ICON_WIDTH = 45; // The width of the icon image plus some padding.
+ var offset = Math.ceil(jthis.offset().left);
+ var x = (e.pageX != null) ? e.pageX - offset : // Mouse position.
+ (e.originalEvent != null) ? e.originalEvent.targetTouches[0].pageX - offset : 0; // Touch pos.
+
+ if (x < ICON_WIDTH) {
+ var bindingKey = jthis.text().split("]")[0];
+ bindingKey = bindingKey.split("[")[1];
+ var href = jthis.children("a:first").attr("href");
+ href = href.replace(window.location, "");
+
+ if (href.indexOf("#selected-exchange") == 0) {
+ var queue = $("#bindings .header h1").text().split(" bindings")[0];
+ var exchange = jthis.find("p:last").text();
+ unbind(exchange, queue, bindingKey);
+
+ } else {
+ var queue = jthis.find("p:last").text();
+ var exchange = $("#bindings .header h1").text().split(" bindings")[0];
+ unbind(exchange, queue, bindingKey);
+ }
+ }
+ }
+ };
+
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#bindings") {
+ return;
+ }
+
+ // Get the latest update of the selected object.
+ var queueId = data.queueId;
+ var exchangeId = data.exchangeId;
+ var object = queueId ? qmfui.Queues.getQueue(queueId) : qmfui.Exchanges.getExchange(exchangeId);
+
+ if (object == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ var name = object.name;
+ name = (name == "") ? "''" : name;
+
+ // Populate the page header with the object name.
+ $("#bindings .header h1").text(name + " bindings");
+
+ // Populate the back button with "Queues" or "Bindings" depending on context
+ var backText = "Exchange";
+
+ if (queueId) {
+ backText = "Queue";
+ $("#bindings").addClass("queue");
+ } else {
+ $("#bindings").removeClass("queue");
+ }
+
+ // Using $("#bindings .header a").text(backText) wipes all child elements so use the following.
+ $("#bindings .header a")[0].firstChild.nodeValue = backText;
+
+ // Ensure the correct item on the previous page is set active so it gets highlighted when we slide back.
+ if (queueId) {
+ $("#selected-queue-bindings").children("li").addClass("active");
+ $("#selected-exchange-bindings").children("li").removeClass("active");
+
+ // Add queueId to add-binding URL so add-binding page can automatically populate the queue name.
+ iTablet.renderList($("#bindings-add-binding"), function(i) {
+ return "<li class='pop'><a href='#add-binding?queueId=" + queueId + "'>Add Binding</a></li>";
+ });
+ } else {
+ $("#selected-queue-bindings").children("li").removeClass("active");
+ $("#selected-exchange-bindings").children("li").addClass("active");
+
+ // Add exchangeId to add-binding URL so add-binding page can automatically populate the exchange name.
+ iTablet.renderList($("#bindings-add-binding"), function(i) {
+ return "<li class='pop'><a href='#add-binding?exchangeId=" + exchangeId + "'>Add Binding</a></li>";
+ });
+ }
+
+ // Note that we don't allow bindings to be added to the default direct exchange, QMF exchanges or
+ // queues that are bound to QMF exchanges as doing so may have undesired consequenses.
+ if (PROTECTED_EXCHANGES[name] || object._isQmfQueue) {
+ $("#bindings-add-binding").hide();
+ $("#bindings .page h1").addClass("first");
+ } else {
+ $("#bindings-add-binding").show();
+ $("#bindings .page h1").removeClass("first");
+ }
+
+ // Render selected queue's bindings to #queue-details-bindings.
+ var bindings = qmfui.Console.getBindings();
+ var binding = [];
+ for (var i in bindings) {
+ var b = bindings[i];
+ if (b.queueRef == queueId) {
+ var exchange = qmfui.Exchanges.getExchange(b.exchangeRef); // Dereference exchangeRef
+ if (exchange != null) {
+ var ename = exchange.name;
+ if (ename == "") {
+ // Note that we don't allow bindings to be deleted from default direct exchange.
+ binding.push("<li class='arrow'><a href='#selected-exchange?id=" +
+ b.exchangeRef + "&bindingKey=" + b.bindingKey + "'>" +
+ "bind [" + b.bindingKey + "] => <p>''</p></a></li>");
+ } else {
+ var text = render(exchange, b);
+
+ // Note that we don't allow bindings to be deleted from QMF exchanges.
+ if (PROTECTED_EXCHANGES[ename]) {
+ binding.push("<li class='multiline arrow'><a href='#selected-exchange?id=" +
+ b.exchangeRef + "&bindingKey=" + b.bindingKey + "'>" +
+ "<div>bind [" + b.bindingKey + "] =></div>" +
+ "<div>" + text + "<p>" + ename + "</p></div></a></li>");
+ } else {
+ binding.push("<li class='multiline arrow clickable-icon'><a class='delete' href='#selected-exchange?id=" +
+ b.exchangeRef + "&bindingKey=" + b.bindingKey + "'>" +
+ "<div>bind [" + b.bindingKey + "] =></div>" +
+ "<div>" + text + "<p>" + ename + "</p></div></a></li>");
+ }
+ }
+ }
+ } else if (b.exchangeRef == exchangeId) {
+ var queue = qmfui.Queues.getQueue(b.queueRef); // Dereference queueRef
+ if (queue != null) {
+ var qname = queue.name;
+ var ename = object.name; // object is actually exchange in this case.
+ var text = render(object, b);
+
+ // Note that we don't allow bindings to be deleted from default direct or QMF exchanges.
+ if (PROTECTED_EXCHANGES[ename]) {
+ binding.push("<li class='multiline arrow'><a href='#selected-queue?id=" +
+ b.queueRef + "&bindingKey=" + b.bindingKey + "'>" +
+ "<div>bind [" + b.bindingKey + "] =></div>" +
+ "<div>" + text + "<p class='fullwidth'>" + qname + "</p></div></a></li>");
+
+ } else {
+ binding.push("<li class='multiline arrow clickable-icon'><a class='delete' href='#selected-queue?id=" +
+ b.queueRef + "&bindingKey=" + b.bindingKey + "'>" +
+ "<div>bind [" + b.bindingKey + "] =></div>" +
+ "<div>" + text + "<p class='fullwidth'>" + qname + "</p></div></a></li>");
+ }
+ }
+ }
+ }
+
+ if (binding.length == 0) {
+ iTablet.renderList($("#bindings-list"), function(i) {
+ return "<li class='grey'><a href='#'>There are currently no bindings to " + name + "</a></li>";
+ });
+ } else {
+ iTablet.renderList($("#bindings-list"), function(i) {
+ return binding[i];
+ }, binding.length);
+
+ // If _highlightedObject has been set by qmfui.SelectedQueue or qmfui.SelectedExchange search for
+ // the list item that would have caused navigation to that page and set it active, which causes
+ // it to be given a highlight that fades as we navigate back to qmfui.Bindings.
+ if (_highlightedObject) {
+ $("#bindings-list li").each(function() {
+ var li = $(this);
+ // Find the HTML that contains the highlightedObject string and highlightedObjectKey string.
+ var html = li.html();
+ if (html.search(_highlightedObject) != -1 && html.search(_highlightedObjectKey) != -1) {
+ li.addClass("active");
+ }
+ });
+
+ _highlightedObject = null;
+ _highlightedObjectKey = null;
+ }
+ }
+ }
+ };
+
+ /**
+ * This method is called by qmfui.SelectedQueue or qmfui.SelectedExchange to allow qmfui.Bindings to set the
+ * correct list item highlighting to allow it to fade out as we navigate back to qmfui.Bindings. This is necessary
+ * because we maintain a singleton qmfui.Bindings page and as such its state will get modified as we navigate
+ * through multiple queue->binding->exchange->binding etc. Setting the name of the most recent page navigated
+ * to in this method allows the fading to be handled correctly.
+ */
+ this.setHighlightedBinding = function(name, bindingKey) {
+ _highlightedObject = name;
+ _highlightedObjectKey = "bindingKey=" + bindingKey; // Binding keys are always rendered within square braces.
+ };
+
+ this.initialise = function() {
+ $("#bindings").unbind("show").bind("show", qmfui.Bindings.update);
+
+ // Using a click handler here doesn't seem to have the 300ms delay that occurs when using click handlers
+ // attached to anchors (hence why those use END_EV). It's *probably* because this is a delegating handler.
+ // JavaScript alert() can interfere with touchend so it's generally better to use click() if it's possible
+ // to do so without it causing that irritating delay!!
+ $("#bindings-list").click(clickHandler);
+ };
+}; // End of qmfui.Bindings definition
+
+
+/**
+ * Create a Singleton instance of the AddBinding class managing the id="add-binding" page.
+ */
+qmfui.AddBinding = new function() {
+ // Protected Exchanges are exchanges that we don't permit binding to - default direct and the QMF exchanges.
+ var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true,
+ "qmf.default.topic": true, "qpid.management": true};
+ var _queueName = "";
+ var _exchangeName = "";
+ var _exchangeType = "";
+ var _properties = {};
+
+ /**
+ * Actually add the new binding using the QMF create method.
+ */
+ var submit = function() {
+ if (_exchangeType == "headers") {
+ _properties["x-match"] = $("#x-match input[checked]").val();
+ } else if (_exchangeType == "xml") {
+ _properties = {};
+ var textarea = $("#add-xml-binding textarea");
+ var xquery = textarea.val();
+ if (xquery == "") {
+ textarea.addClass("error");
+ return;
+ } else {
+ textarea.removeClass("error");
+ _properties["xquery"] = xquery;
+ }
+ } else {
+ _properties = {};
+ }
+
+ var bindingKey = $("#add-binding-key-name").val();
+ var bindingIdentifier = _exchangeName + "/" + _queueName;
+ if (bindingKey != "") {
+ bindingIdentifier = bindingIdentifier + "/" + bindingKey;
+ }
+
+ // Before we actually add the new binding check to see if a binding with specified bindingIdentifier currently
+ // exists. It's a slight faff, but the Qpid broker doesn't currently detect this condition.
+ var duplicateKey = false;
+ var bindings = qmfui.Console.getBindings();
+ for (var i in bindings) {
+ var b = bindings[i];
+ // If a binding with the chosen key is found check if the queue and exchange names match.
+ if (b.bindingKey == bindingKey) {
+ var exchange = qmfui.Exchanges.getExchange(b.exchangeRef); // Dereference the exchangeRef.
+ if (exchange != null && exchange.name == _exchangeName) {
+ var queue = qmfui.Queues.getQueue(b.queueRef); // Dereference the queueRef.
+ if (queue != null && queue.name == _queueName) {
+ duplicateKey = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (duplicateKey) {
+ alert('A binding with the identifier "' + bindingIdentifier + '" aleady exists.');
+ } else {
+ var arguments = {"type": "binding", "name": bindingIdentifier, "properties": _properties};
+ var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object.
+ broker.invokeMethod("create", arguments, function(data) {
+ if (data.error_text) {
+ alert(data.error_text);
+ } else {
+ iTablet.location.back();
+ }
+ });
+ }
+
+ // Delete the x-match and xquery properties. Note that the other properties are retained, this is
+ // deliberate because it's quite often the case that one may wish to add several headers bindings
+ // that may only differ slightly, it's pretty quick to delete match values that aren't needed.
+ delete _properties["x-match"];
+ delete _properties["xquery"];
+ };
+
+ /**
+ * This method renders the main add-binding page when it is made visible by the show event being triggered.
+ * It tries to be fairly clever by populating either the queue name or exchange name depending on where
+ * add-binding was navigated from. If a queueId or exchangeId isn't available navigation is added to the
+ * add-binding-select-queue or add-binding-select-exchange page by adding the arrow class to
+ * add-binding-queue-name or add-binding-exchange-name. This method then checks the exchange type and
+ * provides additional rendering necessary for XML or Headers exchanges.
+ */
+ var show = function() {
+ var location = iTablet.location;
+ var data = location.data;
+
+ if (data == null || location.hash != "#add-binding") {
+ return;
+ }
+
+ var queueId = data.queueId;
+ var exchangeId = data.exchangeId;
+
+ if (queueId) {
+ var queue = qmfui.Queues.getQueue(queueId);
+ _queueName = (queue == null) ? "" : queue.name;
+ _exchangeName = $("#add-binding-select-exchange input[checked]").val();
+ var exchange = qmfui.Exchanges.getExchangeByName(_exchangeName);
+ _exchangeType = (exchange == null) ? "" : exchange.type;
+
+ $("#add-binding-queue-name").removeClass("arrow");
+ $("#add-binding-exchange-name").addClass("arrow");
+ } else {
+ _queueName = $("#add-binding-select-queue input[checked]").val();
+ var exchange = qmfui.Exchanges.getExchange(exchangeId);
+ _exchangeName = (exchange == null) ? "" : exchange.name;
+ _exchangeType = (exchange == null) ? "" : exchange.type;
+
+ $("#add-binding-queue-name").addClass("arrow");
+ $("#add-binding-exchange-name").removeClass("arrow");
+ }
+
+ var typeText = (_exchangeType == "") ? "" : " (" + _exchangeType + ")";
+
+ $("#add-binding-queue-name p").text(_queueName);
+ $("#add-binding-exchange-name p").text(_exchangeName + typeText);
+
+ if (_exchangeType == "headers") {
+ // Render the properties and navigation needed to populate Headers bindings. These are dynamically
+ // populated and updated as Headers key/value properties get added or deleted.
+ $("#add-binding div.page h1").show().text("Headers");
+ $("#add-headers-binding").show();
+ $("#add-xml-binding").hide();
+
+ var list = [];
+ list.push("<li class='arrow'><a href='#x-match'>Match<p>" + $("#x-match input[checked]").val() + "</p></a></li>");
+
+ for (var i in _properties) {
+ var key = i;
+ var value = _properties[i];
+ // Note we add key/value to the query part of the URL too to let showHeaderMatch() populate the values.
+ list.push("<li class='arrow clickable-icon'><a class='delete' href='#add-header-match?key=" + key + "&value=" + value + "'>" + key + "<p>" + value + "</p></a></li>");
+ }
+
+ list.push("<li class='arrow'><a href='#add-header-match'>Add...</a></li>");
+
+ iTablet.renderList($("#add-headers-binding"), function(i) {
+ return list[i];
+ }, list.length);
+ } else if (_exchangeType == "xml") {
+ $("#add-binding div.page h1").show().text("XML");
+ $("#add-xml-binding").show();
+ $("#add-headers-binding").hide();
+ } else {
+ $("#add-binding div.page h1").hide();
+ $("#add-headers-binding").hide();
+ $("#add-xml-binding").hide();
+ }
+ };
+
+ /**
+ * This method renders the add-binding-select-exchange page when its show event is triggered. This page
+ * needs a show handler because it needs to be dynamically updated as the exchanges available in the radio
+ * button selection set will vary as exchanges get added or deleted.
+ */
+ var showSelectExchange = function() {
+ var exchanges = qmfui.Console.getExchanges();
+ var filteredExchanges = [];
+ var currentlySelected = $("#add-binding-exchange-name p").text();
+
+ // Check the status of any Exchange that the user may have previously selected prior to hitting "Done".
+ if (currentlySelected != "None (default)") {
+ // Remove the exchange type from the text before testing.
+ currentlySelected = currentlySelected.split(" (")[0];
+ if (qmfui.Exchanges.getExchangeByName(currentlySelected) == null) { // Check if it has been deleted.
+ alert('The currently selected Exchange "' + currentlySelected + '" appears to have been deleted.');
+ currentlySelected = "None (default)";
+ }
+ }
+
+ var checked = (currentlySelected == "None (default)") ? "checked" : "";
+ filteredExchanges.push("<li><label for='add-binding-exchangeNone'>None (default)</label><input type='radio' id='add-binding-exchangeNone' name='add-binding-select-exchange' value='None (default)' " + checked + "/></li>");
+
+ var length = exchanges.length;
+ for (var i = 0; i < length; i++) {
+ var name = exchanges[i].name;
+ var type = exchanges[i].type;
+ checked = (currentlySelected == name) ? "checked" : "";
+
+ // Filter out default direct and QMF exchanges as we don't want to allow binding to those.
+ if (!PROTECTED_EXCHANGES[name]) {
+ filteredExchanges.push("<li><label for='add-binding-exchange" + i + "'>" + name + " (" + type + ")</label><input type='radio' id='add-binding-exchange" + i + "' name='add-binding-select-exchange' value='" + name + "' " + checked + "/></li>");
+ }
+ }
+
+ iTablet.renderList($("#add-binding-select-exchange-list"), function(i) {
+ return filteredExchanges[i];
+ }, filteredExchanges.length);
+ };
+
+ /**
+ * This method renders the add-binding-select-queue page when its show event is triggered. This page
+ * needs a show handler because it needs to be dynamically updated as the queues available in the radio
+ * button selection set will vary as queues get added or deleted.
+ */
+ var showSelectQueue = function() {
+ var queues = qmfui.Console.getQueues();
+ var filteredQueues = [];
+ var currentlySelected = $("#add-binding-queue-name p").text();
+
+ // Check the status of any Queue that the user may have previously selected prior to hitting "Done".
+ if (currentlySelected != "None (default)") {
+ if (qmfui.Queues.getQueueByName(currentlySelected) == null) { // Check if it has been deleted.
+ alert('The currently selected Queue "' + currentlySelected + '" appears to have been deleted.');
+ currentlySelected = "None (default)";
+ }
+ }
+
+ var checked = (currentlySelected == "None (default)") ? "checked" : "";
+ filteredQueues.push("<li><label for='add-binding-queueNone'>None (default)</label><input type='radio' id='add-binding-queueNone' name='add-binding-select-queue' value='None (default)' " + checked + "/></li>");
+
+ var length = queues.length;
+ for (var i = 0; i < length; i++) {
+ var name = queues[i].name;
+ // We do getQueueByName(name) because the _isQmfQueue property is a "fake" property added by the
+ // qmfui.Queues class, it's only stored in QMF objects held in the getQueueByName() and getQueue() caches.
+ var isQmfQueue = qmfui.Queues.getQueueByName(name)._isQmfQueue;
+ checked = (currentlySelected == name) ? "checked" : "";
+
+ // Filter out queues bound to QMF exchanges as we don't want to allow additional binding to those.
+ if (!isQmfQueue) {
+ filteredQueues.push("<li><label for='add-binding-queue" + i + "'>" + name + "</label><input type='radio' id='add-binding-queue" + i + "' name='add-binding-select-queue' value='" + name + "' " + checked + "/></li>");
+ }
+ }
+
+ iTablet.renderList($("#add-binding-select-queue-list"), function(i) {
+ return filteredQueues[i];
+ }, filteredQueues.length);
+ };
+
+ /**
+ * This method renders the add-header-match page when its show event is triggered. This page
+ * needs a show handler because it needs to be dynamically updated with any previously selected key/value pairs.
+ */
+ var showHeaderMatch = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ var key = "";
+ var value = "";
+
+ if (data != null && location.hash == "#add-header-match") {
+ key = data.key;
+ value = data.value;
+ }
+
+ $("#header-match-key").val(key);
+ $("#header-match-value").val(value);
+ };
+
+ /**
+ * Adds a a header match value from the binding being populated.
+ * This is triggered by the "Done" button on the add-header-match page. There's some validation logic
+ * in place to ensure that a key and value are both supplied.
+ */
+ var addHeaderMatch = function() {
+ var key = $("#header-match-key");
+ var keyVal = key.val();
+ var value = $("#header-match-value");
+ var valueVal = value.val();
+
+ if (keyVal == "") {
+ key.addClass("error");
+ } else {
+ key.removeClass("error");
+ }
+
+ if (valueVal == "") {
+ value.addClass("error");
+ } else {
+ value.removeClass("error");
+ }
+
+ if (keyVal != "" && valueVal != "") {
+ _properties[keyVal] = valueVal;
+ iTablet.location.back();
+ }
+ };
+
+ /**
+ * Removes a header match value from the binding being populated.
+ * This handler is triggered by clicking a <li class="clickable-icon">. Unfortunately there's bit more work
+ * to do because we only want to respond if the actual icon has been clicked so we need to work out the
+ * mouse or tap position within the li and check it's less than the icon width.
+ * Once we're happy that we've clicked the icon we need to work out which binding the <li> relates to. The
+ * approach to this is a little messy and involves scraping some of the html associated with the <li>
+ */
+ var removeHeaderMatch = function(e) {
+ var target = e.target;
+ var jthis = $(target).closest("ul li.clickable-icon");
+
+ if (jthis.length != 0) {
+ var ICON_WIDTH = 45; // The width of the icon image plus some padding.
+ var offset = Math.ceil(jthis.offset().left);
+ var x = (e.pageX != null) ? e.pageX - offset : // Mouse position.
+ (e.originalEvent != null) ? e.originalEvent.targetTouches[0].pageX - offset : 0; // Touch pos.
+
+ if (x < ICON_WIDTH) {
+ var key = jthis.children("a:first")[0].firstChild.nodeValue;
+ delete _properties[key];
+ $("#add-binding").trigger("show");
+ }
+ }
+ };
+
+ this.initialise = function() {
+ $("#add-binding").unbind("show").bind("show", show);
+ $("#add-binding-select-exchange").unbind("show").bind("show", showSelectExchange);
+ $("#add-binding-select-queue").unbind("show").bind("show", showSelectQueue);
+ $("#add-header-match").unbind("show").bind("show", showHeaderMatch);
+
+ // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers.
+ $("#add-binding .right.button").bind(qmfui.END_EV, submit);
+ $("#add-header-match .right.button").bind(qmfui.END_EV, addHeaderMatch);
+
+ // Always initialise to default value irrespective of browser caching.
+ $("#x-match-all").click();
+
+ // Using a click handler here doesn't seem to have the 300ms delay that occurs when using click handlers
+ // attached to anchors (hence why those use END_EV). It's *probably* because this is a delegating handler.
+ // JavaScript alert() can interfere with touchend so it's generally better to use click() if it's possible
+ // to do so without it causing that irritating delay!!
+ $("#add-headers-binding").click(removeHeaderMatch);
+ };
+}; // End of qmfui.AddBinding definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+// Generic Graph Rendering Page
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Graphs class managing the id="graphs" page.
+ */
+qmfui.Graphs = new function() {
+ var IS_IE = (navigator.appName == "Microsoft Internet Explorer");
+ var IE_VERSION = IS_IE ? /MSIE (\d+)/.exec(navigator.userAgent)[1] : -1;
+
+ var SECONDS_AS_NANOS = 1000000000; // One second represented in nanoseconds.
+ var MILLIS_AS_NANOS = 1000000; // One millisecond represented in nanoseconds.
+ var HEIGHT = 300; // Canvas height (including radiused borders).
+ var BORDER = 10;
+
+ var _ctx = null;
+
+ var _radius = new Image();
+ _radius.src = "/itablet/images/ie/radius-10px-sprite.png";
+
+ /**
+ * qmfui is pretty much browser neutral as browser quirks have been taken care of by jQuery and the
+ * iTablet framework but canvas support is an edge case. Wrapping a canvas in a <li> doesn't seem to
+ * work (<li> is where most of the fake border radius stuff is done), so for canvas we simply use the
+ * canvas rendering itself and use drawImage() to render radius-10px-sprite.png. We use IE_VERSION
+ * from iTablet to detect the IE version as we only draw borders for IE 7 & 8 as IE9 has fake border-radius
+ * support and for IE6 radiused borders haven't been done at all because life is too short......
+ */
+ var drawBorderRadius = function(context) {
+ if (IE_VERSION == 8 || IE_VERSION == 7) {
+ var width = context.canvas.width;
+ var height = context.canvas.height;
+
+ // Draw the border lines.
+ context.beginPath();
+ // Drawing mid point of a pixel e.g. starting at 0.5 is important for getting one pixel lines.
+ context.rect(0.5, 0.5, width - 2, height - 2);
+ context.strokeStyle = "black";
+ context.stroke(); // Draw new path
+
+ // Render the radiused borders from the radius-10px-sprite.png sprite using canvas drawImage().
+ context.drawImage(_radius, 0, 0, 10, 10, 0, 0, 10, 10);
+ context.drawImage(_radius, 0, 10, 10, 10, 0, height - 10, 10, 10);
+ context.drawImage(_radius, 10, 0, 10, 10, width - 10, 0, 10, 10);
+ context.drawImage(_radius, 10, 10, 10, 10, width - 10, height - 10, 10, 10);
+ }
+ };
+
+
+ /**
+ * Aaaargh. Another IE edge case!!
+ * IE7 has very quirky behaviour - using $("#graphs-time-selector").innerWidth() is unreliable, it
+ * fails when page is initially shown and calling it also seems to cause the page to take a long
+ * time to re-render on resize. Using the width of body doesn't have that issue but getting the
+ * css left value of graphs is unreliable too!!! so I've just coded the values of LEFT & PAGE_WIDTH.
+ */
+ var getWidth = function() {
+ if (IE_VERSION == 7) {
+ var LEFT = 251; // .main css left,
+ var PAGE_WIDTH = 0.9; // .page 100% - padding left + right
+ var width = $("body").outerWidth();
+ width = Math.floor((width - LEFT) * PAGE_WIDTH - 0.5);
+ return width;
+ } else {
+ return ($("#graphs-time-selector").innerWidth() - 2); // The -2 compensates for the border width.
+ }
+ };
+
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#graphs") {
+ return;
+ }
+
+ // Get the latest update of the selected object and populate the text of the back button.
+ var object = null;
+ var backText = "Unknown";
+
+ if (data.queueId) {
+ object = qmfui.Queues.getQueue(data.queueId);
+ backText = "Queue";
+ $("#graphs").removeClass("exchange connection");
+ } else if (data.exchangeId) {
+ object = qmfui.Exchanges.getExchange(data.exchangeId);
+ backText = "Exchange";
+ $("#graphs").addClass("exchange").removeClass("connection");
+ } else if (data.connectionId) {
+ object = qmfui.Connections.getConnection(data.connectionId);
+ backText = "Connect...";
+ $("#graphs").addClass("connection").removeClass("exchange");
+ }
+
+ if (object == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ var property = data.property; // An index to the particular property to be displayed.
+ var statistics = object._statistics;
+
+ if (statistics == null) {
+ return;
+ }
+
+ var description = statistics.description[property]; // Lookup the description of the property.
+ var isRate = (description == "msgDepth") ? false : true; // Is the statistic a rate.
+
+ // Populate the page header with the property being graphed.
+ var header = (object.name == null) ? object.address + " " + description : object.name + " " + description;
+ $("#graphs .header h1").text(header);
+
+ // Using $("#graphs .header a").text(backText) wipes all child elements so use the following.
+ $("#graphs .header a")[0].firstChild.nodeValue = backText;
+
+ // Populate the graph title with the property being graphed.
+ if (isRate) {
+ description += " " + statistics.getRate(property).toFixed(2) + "/sec"
+ } else if (!statistics.short.isEmpty()) {
+ description += " " + statistics.short.getLast()[property];
+ }
+ $("#graphs .page h1").text(description);
+
+ var width = getWidth();
+ if (_ctx) {
+ if (width != _ctx.canvas.width) {
+ _ctx.canvas.width = width;
+ }
+
+ _ctx.clearRect(0, 0, width, HEIGHT); // Clear previous image.
+ drawBorderRadius(_ctx); // Draw fake border radius on old versions of IE.
+
+ _ctx.beginPath(); // Start drawing path for grid.
+ for (var i = BORDER + 0.5; i < width; i += ((width - (BORDER*2))/10)) { // Draw vertical lines
+ _ctx.moveTo(i, BORDER);
+ _ctx.lineTo(i, HEIGHT - BORDER);
+ }
+
+ for (var i = BORDER + 0.5; i < HEIGHT; i += ((HEIGHT - (BORDER*2))/10)) { // Draw horizontal lines
+ _ctx.moveTo(BORDER, i);
+ _ctx.lineTo(width - BORDER, i);
+ }
+ _ctx.strokeStyle = "#dddddd";
+ _ctx.stroke(); // Draw grid.
+ }
+
+ var stats = statistics.short; // 10 mins
+ var period = 600*SECONDS_AS_NANOS; // 600 seconds (ten minutes) in nanoseconds.
+ var interval = $("#graphs-time-selector input:radio[checked]").val();
+ if (interval == "oneHour") {
+ stats = statistics.medium; // 1 hr
+ period = 3600*SECONDS_AS_NANOS; // 3600 seconds (one hour) in nanoseconds.
+
+ } else if (interval == "oneDay") {
+ stats = statistics.long; // 1 day
+ period = 24*3600*SECONDS_AS_NANOS; // 24*3600 seconds (one day) in nanoseconds.
+ }
+
+ var size = stats.size();
+ var isMinimumSize = isRate ? size > 1 : size > 0;
+
+ if (isMinimumSize && _ctx) {
+ /*
+ * For reasons of memory efficiency statistics are stored in ring buffers and attached to certain
+ * management objects (queue, exchange & connection) we only record statistics for certain properties
+ * of these management objects. For efficiency each item stored in the ring buffer is an array
+ * containing the statistics for each stored property with the last array item being the update
+ * timestamp of the management object. Thus the timestamp for each statistic sample is the last
+ * item (length - 1) of the array. Getting the length of any item held in the stats ring buffer
+ * gives us the index to use to lookup the timestamp, we use getLast() for convenience get(0) would
+ * be fine too. The isMinimumSize test ensures we have at least one item in the stats ring buffer.
+ */
+ var TIMESTAMP = stats.getLast().length - 1;
+
+ var curtime = (+new Date() * MILLIS_AS_NANOS); // Current time represented in nanoseconds.
+ var minimumTimestamp = curtime - period; // Items with timestamps less than this aren't in this period.
+ var limit = isRate ? size - 1 : size; // Maximum number of sample points.
+ var graph = [limit]; // Create an array to hold the data we'll put into the graph plot.
+ var count = 0; // This will be the actual number of sample points that fall within this period.
+ var i = 0; // Index into statistics circular buffer.
+
+ // Skip over statistics older than the graph period. Mostly this won't happen, but for things like
+ // iOS where the browser may sleep/hibernate there may be a considerable gap between samples.
+ while ((i < limit) && (stats.get(i)[TIMESTAMP] < minimumTimestamp)) i++;
+
+ var maxValue = 0;
+ for (;i < limit; i++, count++) { // i starts with the minimum index, count starts at zero.
+ var sample = stats.get(i); // Get each statistic sample from the circular buffer.
+ var value = sample[property]; // Get the sample value.
+ var timestamp = sample[TIMESTAMP]; // Get the sample timestamp.
+
+ if (isRate) {
+ var sample1 = stats.get(i + 1); // Get the next sample so we can calculate the rate.
+ var value1 = sample1[property]; // Get the next sample's value.
+ var timestamp1 = sample1[TIMESTAMP];// Get the next sample's timestamp.
+ value = ((value1 - value)*SECONDS_AS_NANOS)/(timestamp1 - timestamp); // Rate in items/s
+ }
+
+ var x = width + (timestamp - curtime)*(width/period);
+ graph[count] = {x: x, y: value};
+
+ if (value > maxValue) {
+ maxValue = value;
+ }
+ }
+
+ var heightNormaliser = (HEIGHT - (2*BORDER))/maxValue;
+
+ _ctx.beginPath(); // Start drawing path for main graph.
+ var sample = graph[0];
+ _ctx.moveTo(sample.x, (maxValue - sample.y)*heightNormaliser + BORDER);
+
+ for (i = 1; i < count; i++) {
+ sample = graph[i];
+ _ctx.lineTo(sample.x, (maxValue - sample.y)*heightNormaliser + BORDER);
+ }
+ _ctx.strokeStyle = "black";
+ _ctx.stroke(); // Draw main graph.
+
+ // Draw grid text
+ _ctx.font = "15px Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif";
+ _ctx.fillStyle = "red";
+ _ctx.textBaseline = "middle";
+ _ctx.textAlign = "right";
+ _ctx.fillText(maxValue.toFixed(2), width - BORDER, BORDER);
+ _ctx.fillText((maxValue/2).toFixed(2), width - BORDER, HEIGHT/2);
+ _ctx.fillText("0.00", width - BORDER, HEIGHT - BORDER);
+ }
+ }
+ };
+
+ this.initialise = function() {
+ $(document).bind("orientationchange", qmfui.Graphs.update);
+ $(window).resize(qmfui.Graphs.update);
+ $("#graphs").unbind("show").bind("show", qmfui.Graphs.update);
+ $("#graphs-time-selector input").change(qmfui.Graphs.update);
+
+ var canvas = $("#graphs-canvas")[0];
+ if (canvas != null) {
+ // The following "shouldn't" be necessary as the graphs-canvas is part of the static markup and it
+ // works in the author's IE8 XP and Win7 test VMs without it, however getContext("2d") doesn't seem
+ // to be working on some IE8 deployments so it's added experimentally to see if it fixes the problem.
+ if (IS_IE && IE_VERSION == 8 && typeof(G_vmlCanvasManager) != "undefined") {
+ G_vmlCanvasManager.initElement(canvas);
+ }
+
+ canvas.height = HEIGHT;
+ if (canvas.getContext) { // Is canvas supported?
+ _ctx = canvas.getContext("2d");
+ }
+ }
+ };
+}; // End of qmfui.Graphs definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+
+
+/**
+ * Create a Singleton instance of the Links class managing the id="links" page.
+ * TODO Add link/bridge features.
+ */
+qmfui.Links = new function() {
+
+ this.update = function() {
+
+ };
+
+ this.initialise = function() {
+ };
+}; // End of qmfui.Links definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the RouteTopology class managing the id="route-topology" page.
+ * TODO Add link/bridge features. The idea of the route topology page is to "discover" federated brokers linked
+ * to a "seed" broker. Not sure if this is actually possible, but it'd be pretty cool.
+ */
+qmfui.RouteTopology = new function() {
+
+ this.initialise = function() {
+ };
+}; // End of qmfui.RouteTopology definition
+
+
+//-------------------------------------------------------------------------------------------------------------------
+
+/**
+ * Create a Singleton instance of the Events class managing the id="events" page.
+ */
+qmfui.Events = new function() {
+ var _events = new util.RingBuffer(20); // Store the Event history in a circular buffer.
+
+ this.getEvent = function(index) {
+ return _events.get(index);
+ };
+
+ this.update = function(workItem) {
+ if (workItem._type == "EVENT_RECEIVED") {
+ var params = workItem._params;
+ var agent = params.agent;
+
+ if (agent._product == "qpidd") { // Only log events from the broker ManagementAgent
+ _events.put(params.event);
+ iTablet.renderList($("#events-list"), function(i) {
+ var event = _events.get(i);
+ var name = event._schema_id._class_name;
+ var timestamp = new Date(event._timestamp/1000000).toLocaleString();
+ var text = name;
+
+ return "<li class='multiline arrow'><a href='#selected-event?index=" + i + "'>" + i + " " + text +
+ "<p class='sub'>" + timestamp + "</p></a></li>";
+ }, _events.size());
+ }
+ }
+ };
+}; // End of qmfui.Events definition
+
+/**
+ * Create a Singleton instance of the SelectedEvent class managing the id="selected-event" page.
+ */
+qmfui.SelectedEvent = new function() {
+ var _severities = ["emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"];
+
+ this.update = function() {
+ var location = iTablet.location;
+ var data = location.data;
+ if (data == null || location.hash != "#selected-event") {
+ return;
+ }
+
+ // Get the latest update of the selected event object.
+ var index = parseInt(data.index); // The parseInt is important! Without it the index lookup gives odd results..
+ var event = qmfui.Events.getEvent(index);
+
+ if (event == null) {
+ $("#resource-deleted").show();
+ } else {
+ $("#resource-deleted").hide();
+
+ // Populate the page header with the event name.
+ var name = event._schema_id._package_name + ":" + event._schema_id._class_name;
+ $("#selected-event .header h1").text(name);
+
+ var general = [];
+ var timestamp = new Date(event._timestamp/1000000).toLocaleString();
+ general.push("<li><a href='#'>timestamp<p>" + timestamp + "</p></a></li>");
+ general.push("<li><a href='#'>severity<p>" + _severities[event._severity] + "</p></a></li>");
+
+ iTablet.renderList($("#selected-event-list"), function(i) {
+ return general[i];
+ }, general.length);
+
+ var values = [];
+ for (var i in event._values) { // Populate with event _values properties.
+ var value = event._values[i];
+ if (i == "args" || i == "properties") { // If there are any args try and display them.
+ value = util.stringify(value);
+ }
+ values.push("<li><a href='#'>" + i + "<p>" + value + "</p></a></li>");
+ }
+
+ iTablet.renderList($("#selected-event-values"), function(i) {
+ return values[i];
+ }, values.length);
+ }
+ };
+
+ this.initialise = function() {
+ $("#selected-event").unbind("show").bind("show", qmfui.SelectedEvent.update);
+ };
+}; // End of qmfui.SelectedEvent definition
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/LICENCE b/qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/LICENCE
new file mode 100644
index 0000000000..e62925ae88
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/LICENCE
@@ -0,0 +1,23 @@
+/*
+ * qpid.js
+ *
+ * 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.
+ *
+ */
+
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/qpid.js b/qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/qpid.js
new file mode 100644
index 0000000000..f1ad4711f2
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/qpid/scripts/qpid.js
@@ -0,0 +1,745 @@
+/**
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This library provides a JavaScript implementation of the QMF2 API (and TODO qpid::messaging - some code is in place
+ * for Connection as necessary to implement the QMF2 API the rest will follow in due course.
+ *
+ * This implementation of the QMF2 API relies on the Qpid REST API as a back end server and the QMF2 API methods
+ * are basically proxies by the Qpid REST API to a real QMF2 Console implemented on the back end. Note that this
+ * implementation uses AJAX/REST over pure HTTP which results in some inefficiencies, in particular the mechanism
+ * used to retrieve QMF2 Events (getWorkItem()) uses the AJAX long-polling pattern. It should be possible to
+ * provide an alternative implementation using WebSockets, the main two reasons that this hasn't been done are.
+ * 1) The author lacks familiarity with WebSockets....
+ * 2) WebSockets have much poorer cross-browser support, though to be fair that could be mitigated using a
+ * WebSocket JavaScript library that could fall back to using HTTP if browser/server support was unavaiable.
+ *
+ * This library also includes a utility package providing a number of useful classes and helper functions. These
+ * aren't strictly part of qpid/qmf JavaScript but stringify() and randomUUID() are used by qpid.js so including
+ * the util package in this library avoids adding yet another dependency.
+ *
+ * It has dependencies on the following:
+ * jquery.js (> 1.5)
+ *
+ * author Fraser Adams
+ */
+
+//-------------------------------------------------------------------------------------------------------------------
+
+// Create a new namespace for the util "package".
+var util = {};
+
+/**
+ * This debug method lists the properties of the specified JavaScript object.
+ * @param obj the object that we wish to list the properties for.
+ " @return a string containing the list of the object's properties pretty printed.
+ */
+util.displayProperties = function(obj) {
+ var result = obj + "\n\n";
+ var count = 0;
+ for (var i in obj) {
+ result += i + ", ";
+ if (count % 4 == 3) result += "\n";
+ count++;
+ }
+ result = result.substring(0, result.lastIndexOf(","));
+ return result;
+};
+
+/**
+ * Stringify an Object into JSON. Uses JSON.stringify if present and if not it uses a quick and dirty serialiser.
+ * @param obj the object that we wish to stringify into JSON.
+ * @return the JSON representation of the specified object.
+ */
+util.stringify = function(obj) {
+ var fromObject = function(obj) {
+ if (Object.prototype.toString.apply(obj) === '[object Array]') {
+ var string = "";
+ var length = obj.length;
+ for (var i = 0; i < length; i++) {
+ string += fromObject(obj[i]);
+ if (i < length - 1) {
+ string += ",";
+ }
+ }
+
+ string = "[" + string + "]";
+ return string;
+ } else if (typeof obj == "object") { // Check if the value part is an ObjectId and serialise appropriately
+ if (!obj) {
+ return "null";
+ }
+
+ var string = "";
+ for (var i in obj) {
+ if (obj.hasOwnProperty(i)) {
+ if (string != "") {
+ string += ",";
+ }
+ string += '"' + i + '":' + fromObject(obj[i]);
+ }
+ }
+
+ string = "{" + string + "}";
+ return string;
+ } else if (typeof obj == "string") {
+ return '"' + obj + '"';
+ } else {
+ return obj.toString();
+ }
+ };
+
+ if (obj == null) {
+ return "";
+ } if (window.JSON && JSON.stringify && typeof JSON.stringify == "function") {
+ return JSON.stringify(obj);
+ } else {
+ var string = fromObject(obj);
+ return string;
+ }
+};
+
+/**
+ * Compact rfc4122v4 UUID from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
+ * @return an rfc4122v4 UUID.
+ */
+util.randomUUID = function() {
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
+ var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
+ return v.toString(16);
+ });
+};
+
+/**
+ * This is a JavaScript port of the "fill count" example from http://en.wikipedia.org/wiki/Circular_buffer
+ * @param size maximum size of the RingBuffer that we want to construct, when items are added beyond this size
+ * they will wrap around.
+ */
+util.RingBuffer = function(size) {
+ var _size = size;
+ var _start = 0;
+ var _count = 0;
+ var _elems = new Array(size);
+
+ /**
+ * @return the maximum size of the RingBuffer.
+ */
+ this.capacity = function() {
+ return _size;
+ };
+
+ /**
+ * @return the number of items currently stored in the RingBuffer.
+ */
+ this.size = function() {
+ return _count;
+ };
+
+ /**
+ * @return true if the buffer is full otherwise return false.
+ */
+ this.isFull = function() {
+ return _count == _size;
+ };
+
+ /**
+ * @return true if the buffer is empty otherwise return false.
+ */
+ this.isEmpty = function() {
+ return _count == 0;
+ };
+
+ /**
+ * Add an item to the end of the buffer, overwriting oldest element if buffer is full.
+ * A client can choose to avoid the overwrite by checking IsFull().
+ * @param the item that we wish to add to the end of the ring buffer.
+ */
+ this.put = function(item) {
+ var end = (_start + _count) % _size;
+ _elems[end] = item;
+ if (_count == _size) {
+ _start = (_start + 1) % _size; // full, overwrite
+ } else {
+ ++_count;
+ }
+ };
+
+ /**
+ * Read and remove oldest item from buffer. N.B. clients must ensure !isEmpty() first.
+ * @return the oldest item from the ring buffer.
+ */
+ this.take = function() {
+ var item = _elems[_start];
+ _start = (_start + 1) % _size;
+ --_count;
+ return item;
+ };
+
+ /**
+ * Read the item at the specified (circular) index non-destructively e.g. index 0 is the first item held in
+ * the ring buffer index size() - 1 is the last item (which is the equivalent of getLast()).
+ * @return the specified ring buffer item.
+ */
+ this.get = function(index) {
+ index = (_start + index) % _size;
+ return _elems[index];
+ };
+
+ /**
+ * @return the last item, or null if no entries are present.
+ */
+ this.getLast = function() {
+ if (_count == 0) {
+ return null;
+ } else {
+ return this.get(_count - 1);
+ }
+ };
+};
+
+
+//-------------------------------------------------------------------------------------------------------------------
+/**
+ * This package is a proxy to the Qpid REST API, which is itself a proxy to a real Qpid API.
+ * It attempts to mimic the Qpid Messaging API where possible (given the asynchronous constraints of JavaScript).
+ */
+
+// Create a new namespace for the qpid "package".
+var qpid = {};
+
+/**
+ * This factory class will attempt to create a Connection object and creates an opaque handle to it internally
+ * which will be used in the URI of subsequent Qpid/QMF calls to the Qpid REST API.
+ *
+ * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Java Connection URL.
+ * @param opts a String containing the options encoded using the same form as the C++ qpid::messaging Connection class.
+ * @return a Connection object which is a proxy to the Qpid REST API, which is itself a proxy to a real Qpid API.
+ */
+qpid.ConnectionFactory = function(url, connectionOptions) {
+
+ /**
+ * This class is a proxy to the Qpid REST API PUT method for creating Connections.
+ * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Java Connection URL.
+ * @param opts a String containing the options encoded using the same form as the C++ qpid::messaging Connection.
+ */
+ var Connection = function(url, connectionOptions) {
+ var _disableEvents = false;
+ var _available = false;
+ var _url = url;
+ var _handle = util.randomUUID();
+ var _defaultCallback = function(connection) {};
+ var _callback = _defaultCallback;
+ var _failureCallback = _defaultCallback;
+
+ /**
+ * The success callback method for the AJAX call invoked by putConnection(). This method marks the
+ * Connection as available and calls the callback method registered by the call to open().
+ */
+ var putConnectionSucceeded = function() {
+ _available = true;
+ _callback(this);
+ };
+
+ /**
+ * The failure callback method for the AJAX call invoked by putConnection(). This method calls the callback
+ * method registered by the call to open().
+ */
+ var putConnectionFailed = function(xhr) {
+ _available = false;
+ _failureCallback(this);
+ };
+
+ /**
+ * Create a Connection object on the REST API via an asynchronous HTTP PUT method.
+ */
+ var putConnection = function() {
+ var data = {url: _url};
+ if (connectionOptions != null && connectionOptions != "") {
+ data.connectionOptions = connectionOptions;
+ }
+
+ if (_disableEvents) {
+ data.disableEvents = true;
+ }
+
+ // Serialise the data Object into a JSON String.
+ data = util.stringify(data);
+
+ $.ajax({
+ type: "PUT",
+ url: "../qpid/connection/" + _handle,
+ cache: false,
+ contentType: "application/json",
+ data: data,
+ timeout: 10000,
+ success: putConnectionSucceeded,
+ error: putConnectionFailed
+ });
+ };
+
+ /**
+ * Remove a Connection object on the REST API via a synchronous HTTP DELETE method.
+ */
+ var deleteConnection = function() {
+ //console.log("**** calling qpid.Connection deleteConnection() ****");
+ /**
+ * Explicitly retrieve the XmlHttpRequest and send the DELETE via a low-level synchronous call because
+ * JQuery 1.8 has deprecated the async: false setting on $.ajax. There's some debate about this - see
+ * http://bugs.jquery.com/ticket/11013 the gist is that synchronous requests can prevent the rest of
+ * the $.ajax plumbing and dependencies from being fixed. In an ideal world asynchronous requests
+ * are almost always preferable, however in mobile Safari (at least) asynchronous calls won't get
+ * fired from onpagehide handlers, which messes up some useful garbage collection when navigating away.
+ * TODO I wonder how delete onpageunload is going to work if I want to use JSONP......
+ */
+ var xhr = $.ajaxSettings.xhr(); // At least we can get the XMLHttpRequest in a platform neutral way.
+ xhr.open("DELETE", "../qpid/connection/" + _handle, false); // Low level synchronous DELETE.
+ xhr.send(null);
+ };
+
+ /**
+ * Calling this method results in a QMF2 Console being created that can only perform synchronous calls such
+ * as getObjects() and can't do asynchronous things like receive Agent updates and QMF2 Events.
+ *
+ * This method must be called besfore addConnection() in order to take effect.
+ */
+ this.disableEvents = function() {
+ _disableEvents = true;
+ }
+
+ /**
+ * Open the Connection object for use.
+ * @param successCallback a handler to be called when open() has successfully established the Qpid Connection.
+ * we include the callback method because JavaScript networking is fundamentally asynchronous so open()
+ * won't block as it would with other languages, the callback provides a way to defer execution of subsequent
+ * code until the Connection is established.
+ * @param failureCallback a handler to be called when open() has failed to established the Qpid Connection.
+ * Note that this will only be called if creating the connection is impossible, that is to say an exception
+ * got thrown by the REST API PUT mothod. If the broker is simply down the Connection proxy will get created
+ * on the server side and the successCallback will be called.
+ */
+ this.open = function(successCallback, failureCallback) {
+ if (successCallback != null) {
+ _callback = successCallback;
+ }
+
+ if (failureCallback != null) {
+ _failureCallback = failureCallback;
+ }
+
+ _available = false;
+ putConnection();
+ };
+
+ /**
+ * Close the Connection object.
+ */
+ this.close = function() {
+ deleteConnection();
+ _available = false;
+ };
+
+ /**
+ * Identify whether the Connection is open for use.
+ * @return true if the Connection is open, otherwise returns false.
+ */
+ this.isAvailable = function() {
+ return _available;
+ };
+
+ /**
+ * Retrieve the Connection's "handle" which is used as part of its URI on the REST API.
+ * @return a String containing the handle UUID.
+ */
+ this.toString = function() {
+ return _handle;
+ };
+ };
+
+ /**
+ * Factory method used to construct a new Connection object.
+ * @return a new Connection object.
+ */
+ this.createConnection = function() {
+ return new Connection(url, connectionOptions);
+ };
+};
+
+//-------------------------------------------------------------------------------------------------------------------
+
+// Create a new namespace for the qmf "package".
+var qmf = {};
+qmf.REFRESH_PERIOD = 10000;
+
+/**
+ * This class is a proxy to the QMF REST API, which is itself a proxy to a real QMF2 Console.
+ * It attempts to mimic the QMF2 API where possible however there are a few deviations because of the entirely
+ * asynchronous nature of JavaScript and AJAX.
+ *
+ * Constructor that provides defaults for name and domain and takes a Notifier/Listener.
+ * @param onEvent a QMFEventListener.
+ */
+qmf.Console = function(onEvent) {
+ var _disableEvents = false;
+ var _connection = null;
+ var _url = "../qpid/connection/";
+ var _qmfEventListenerXHR; // Retain JQuery XHR object for QmfEventListener so we can abort request if needed.
+
+ /**
+ * Send and "AGENT_DELETED" WorkItem for qpidd to the registered Event Listener.
+ */
+ var sendBrokerDisconnectedEvent = function() {
+ var agent = {_vendor: "apache.org", _product: "qpidd", _instance: "1234",
+ _name: "apache.org:qpidd:1234", _epoch: 1, _heartbeat_interval: 10};
+ onEvent({_type: "AGENT_DELETED", _params: {agent: agent}});
+ };
+
+ /**
+ * Send and "AGENT_DELETED" WorkItem for qpid.restapi to the registered Event Listener.
+ */
+ var sendRestApiDisconnectedEvent = function() {
+ var agent = {_vendor: "apache.org", _product: "qpid.restapi", _instance: "1234",
+ _name: "apache.org:qpid.restapi:1234", _epoch: 1, _heartbeat_interval: 10};
+ onEvent({_type: "AGENT_DELETED", _params: {agent: agent}});
+ };
+
+ /**
+ * Retrieve QMF2 WorkItems via the QMF2 REST API, note that this call may block (on the server).
+ */
+ var dispatchEvents = function() {
+ if (_connection != null) {
+ _qmfEventListenerXHR = $.ajax({
+ url: _url + "/console/nextWorkItem",
+ cache: false,
+ dataType: "json",
+ timeout: 3*qmf.REFRESH_PERIOD,
+ success: handleDispatchEventsSuccess,
+ error: handleDispatchEventsFailure
+ });
+ }
+ };
+
+ /**
+ * Success callback method for dispatchEvents. When WorkItems are available they are delivered to the attached
+ * eventListener onEvent callback and dispatchEvents is called again to wait for the next WorkItem.
+ * @param data the QMF2 WorkItem data.
+ */
+ var handleDispatchEventsSuccess = function(data) {
+ if (_connection != null) {
+ onEvent(data);
+ dispatchEvents();
+ }
+ };
+
+ /**
+ * Failure callback method for dispatchEvents. This method sends "AGENT_DELETED" WorkItems to the registered
+ * Event Listener and attempts to re-establish a connection to the REST API and via the the broker.
+ * @param xhr the jQuery XHR object.
+ */
+ var handleDispatchEventsFailure = function(xhr) {
+ //console.log("handleDispatchEventsFailure " + xhr.status + " " + xhr.statusText);
+ if (xhr.status == 0 || xhr.status == 12029) { // For some reason IE7 sends 12029??
+ if (xhr.statusText == "timeout") { // If AJAX calls have timed out it's likely due to a failed broker.
+ sendBrokerDisconnectedEvent();
+ } else {
+ sendRestApiDisconnectedEvent(); // If the status is 0 for another reason the server is probabbly down.
+ }
+ } else if (xhr.status == 404) {
+ // HTTP Not Found. This is most likely to mean that the Console has timed out and been garbage collected
+ // on the REST API Server so we simply attempt to re-open the Qpid Connection.
+ if (_connection != null && _connection.open) {
+ _connection.open();
+ }
+ } else if (xhr.status == 500) {
+ // HTTP Internal Error. Sent by the REST API Server when it knows that the broker has disconnected.
+ sendBrokerDisconnectedEvent();
+ }
+
+ // If the failure wasn't caused by an abort we retry after a timeout.
+ if (xhr.statusText != "abort" && _connection != null) {
+ setTimeout(dispatchEvents, qmf.REFRESH_PERIOD);
+ }
+ };
+
+ /**
+ * Helper method to allow us to get the data from a specified resource from the REST API in the /console/ sub-path
+ * Most of the core QMF2 API mehods can make use of this.
+ * @param resourceName the name of the resource on the REST Server. This is the part of the resource after
+ * the connection e.g. "/console/objects/" + className for the getObjects() call.
+ * @param handler the callback handler if the AJAX GET is successful.
+ * @return the jQuery XHR Object.
+ */
+ var getResource = function(resourceName, handler) {
+ return $.ajax({
+ url: _url + resourceName,
+ cache: false,
+ dataType: "json",
+ timeout: 3*qmf.REFRESH_PERIOD,
+ success: handler
+ });
+ };
+
+ // ******** QmfConsoleData Methods that will be attached to QmfData Objects via makeConsoleData()**********
+
+ /**
+ * Invoke the named method using the supplied inArgs, the response occurs asynchronously and triggers the
+ * named handler method, the outArgs are sent as JSON to the data parameter of the handler method.
+ * Note that this method is intended to be attached to a QmfData JavaScript object. It will use the ObjectId
+ * of the QmfData object to determine the URL resource to POST the data to.
+ */
+ var invokeMethod = function(name, inArgs, handler) {
+ //console.log("calling invokeMethod: " + name + ", oid: " + this._object_id);
+ var defaultHandler = function(data) {};
+
+ var postFailed = function(xhr) {
+ var error = xhr.responseText;
+ if (xhr.status != 500) {
+ error = (xhr.status == 0) ? "POST failed to return correctly." : xhr.statusText;
+ }
+
+ handler({"error_text" : error});
+ };
+
+ inArgs = (inArgs == null || typeof inArgs == "string") ? inArgs : util.stringify(inArgs);
+ handler = (handler == null) ? defaultHandler : handler;
+
+ var data = (inArgs == null) ? '{"_method_name":"' + name + '"}' :
+ '{"_method_name":"' + name + '","_arguments":' + inArgs + '}';
+
+ $.ajax({
+ type: "POST",
+ url: _url + "/object/" + this._object_id,
+ cache: false,
+ headers : {"cache-control": "no-cache"}, // Curtails iOS6 overly aggressive (incorrect!) caching.
+ contentType: "application/json",
+ data: data,
+ timeout: 10000,
+ success: handler,
+ error: postFailed
+ });
+ };
+
+ /**
+ * Request that the Agent updates the value of this object's contents.
+ * @param handler a callback method to handle the asynchronously delivered object refresh.
+ * One slight quirk of the JavaScript implementation is that the state update occurs asynchronously which will
+ * affect code that tries to use the state immediately after a call to object.refresh(). The optional handler
+ * parameter allows client code to defer its code to a callback that gets triggered after the state update.
+ */
+ var refresh = function(handler) {
+ var self = this; // So we use the correct this in the update method....
+
+ var update = function(data) {
+ // Save these timestamps from the original object as they are not correctly populated by the ManagementAgent.
+ var savedCreateTime = self._create_ts;
+ var savedDeleteTime = self._delete_ts;
+
+ if (handler == null) {
+ // If no handler is supplied we update the state of the object itself.
+
+ // Replace all of the current properties with the ones from the JSON response object.
+ for (var i in data) {
+ self[i] = data[i]
+ }
+
+ // Restore the correct timestamps.
+ self._create_ts = savedCreateTime;
+ self._delete_ts = savedDeleteTime;
+ } else {
+ // If a handler is supplied we pass the JSON object returned from the query having set the correct
+ // timestamps and turned back into a QmfConsoleData.
+ // Restore the correct timestamps.
+ data._create_ts = savedCreateTime;
+ data._delete_ts = savedDeleteTime;
+ data.invokeMethod = self.invokeMethod;
+ data.refresh = self.refresh;
+ handler(data);
+ }
+ };
+
+ return getResource("/object/" + this._object_id, update);
+ }
+
+ // ******************************************** Public Methods ********************************************
+
+ /**
+ * Calling this method results in a QMF2 Console being created that can only perform synchronous calls such
+ * as getObjects() and can't do asynchronous things like receive Agent updates and QMF2 Events.
+ * Note that "asynchronous" here relates to the underlying QMF Console created on the Server, as this is a
+ * JavaScript API things like getObjects() results still arrive asynchronously.
+ *
+ * This method must be called besfore addConnection() in order to take effect.
+ */
+ this.disableEvents = function() {
+ _disableEvents = true;
+ }
+
+ /**
+ * Connect the console to the AMQP cloud.
+ *
+ * @param connection a JavaScript qpid.Connection object. Alternatively if the handle string to the Connection
+ * object on the server is known this string can be supplied instead. This is most likely to be the case where
+ * the default QMF Console on the REST API Server is used e.g. by doing _console.addConnection("default");
+ * @param failureCallback a handler to be called when addConnection() has failed to established the Qpid Connection.
+ * Note that this will *only* be called if creating the connection is impossible, that is to say an exception
+ * got thrown by the REST API PUT mothod. If the broker is simply down the Connection proxy will get created
+ * on the server side and the successCallback will be called.
+ */
+ this.addConnection = function(connection, failureCallback) {
+ _connection = connection;
+ _url = _url + _connection.toString();
+
+ if (_connection.open) {
+ if (_disableEvents) {
+ _connection.disableEvents();
+ _connection.open(null, failureCallback);
+ } else {
+ _connection.open(dispatchEvents, failureCallback);
+ }
+ } else { // Use this case if the connection that is passed in is just a string "handle" to the connection
+ dispatchEvents();
+ }
+ };
+
+ /**
+ * Remove the AMQP connection from the console. Un-does the addConnection() operation. Note that because this
+ * API implementation is really a proxy removeConnection() just aborts any AJAX calls for the console.
+ *
+ * @param connection a JavaScript qpid.Connection object
+ */
+ this.removeConnection = function(connection) {
+ if (_connection == connection) {
+ _connection = null;
+
+ if (_qmfEventListenerXHR) {
+ _qmfEventListenerXHR.abort();
+ }
+ }
+ };
+
+ /**
+ * Release the Console's resources.
+ */
+ this.destroy = function() {
+ //console.log("Console.destroy()");
+ this.removeConnection(_connection);
+ };
+
+ /**
+ * Perform a query for QmfData objects. In a difference to the specified QMF2 API rather than returning a list
+ * (possibly empty) of matching objects this JavaScript version triggers a callback, the data parameter of
+ * which contains the list of matching objects. Usage example:
+ * _console.getObjects("broker", function(data) {_objects.broker = data;});
+ *
+ * @param className the class name QMF Management Objects that we wish to retrieve.
+ * TODO packageName and agentName.
+ * @param handler a handler to be called when getObjects() has successfully retrieved the specified objects.
+ * we include the callback method because JavaScript networking is fundamentally asynchronous so getObjects()
+ * won't block as it would with other languages, the callback provides a way to defer execution of subsequent
+ * code until the objects have been returned.
+ * @return returns the jQuery XHR object. In particular the reson for returning this is that it is a "Deferred"
+ * object, what this means is that is can be used to wait until the results from several getObjects() calls
+ * have returned before executing an overall callback.
+ */
+ this.getObjects = function(className, handler) {
+ // TODO allow options to specify Package name and Agent name.
+ return getResource("/console/objects/" + className, handler);
+ };
+
+ /**
+ * The items returned by getObjects are really pure QmfData (really QmfManaged) Objects, they are data Objects
+ * with no methods. This is normally OK because most applications simply want to retrieve the properties/stats
+ * but there are occasions where some of the QmfConsoleData methods are useful. Rather than add the methods
+ * universally this method enables them to be added to specific QmfData instances. This approach is more
+ * efficient as the QmfData objects are created by the browser deserialising JSON and it seems a bit wasteful
+ * to iterate through turning the JSON data into full QmfConsoleData Objects when the methods are rarely used.
+ * @param data the QmfData object that we want to turn into a QmfConsoleData.
+ */
+ this.makeConsoleData = function(data) {
+ data.invokeMethod = invokeMethod;
+ data.refresh = refresh;
+ };
+
+ /**
+ * Get the AMQP address this Console is listening to.
+ *
+ * @param handler a callback method to handle the asynchronously delivered response.
+ * the data passed to the handler contains the console's replyTo address. Note that there are actually two,
+ * there's a synchronous one which is the return address for synchronous request/response type invocations and
+ * there's an asynchronous address with a ".async" suffix which is the return address for asynchronous invocations.
+ * @return returns the jQuery XHR object. See getObjects() documentation for more details on why.
+ *
+ * _console.getAddress(function(data) {console.log(data)}); // Example usage.
+ */
+ this.getAddress = function(handler) {
+ return getResource("/console/address", handler);
+ };
+
+ /**
+ * Gets a list of all known Agents.
+ *
+ * @param handler a callback method to handle the asynchronously delivered response.
+ * the data passed to the handler contains a list of all known Agents as a JSON array each item in the array is
+ * a QMF Agent object in JSON form.
+ * @return returns the jQuery XHR object. See getObjects() documentation for more details on why.
+ *
+ * _console.getAgents(function(data) {console.log(data)}); // Example usage.
+ */
+ this.getAgents = function(handler) {
+ return getResource("/console/agents", handler);
+ };
+
+ /**
+ * Gets the named Agent, if known.
+ *
+ * @param agentName the name of the Agent to be returned.
+ * @param handler a callback method to handle the asynchronously delivered response.
+ * the data passed to the handler is the QMF Agent object in JSON form.
+ * @return returns the jQuery XHR object. See getObjects() documentation for more details on why.
+ *
+ * _console.getAgent("qpidd", function(data) {console.log(data)}); // Example usage.
+ */
+ this.getAgent = function(agentName, handler) {
+ return getResource("/console/agent/" + agentName, handler);
+ };
+
+ /**
+ * In this implementation findAgent() is a synonym for getAgent().
+ */
+ this.findAgent = function(agentName, handler) {
+ return getResource("/console/agent/" + agentName, handler);
+ };
+
+ /**
+ * Gets a list of all known Packages.
+ * @param handler a callback method to handle the asynchronously delivered response.
+ * the data passed to the handler is a list of all available packages as a JSON array.
+ * @return returns the jQuery XHR object. See getObjects() documentation for more details on why.
+ *
+ * _console.getPackages(function(data) {console.log(data)}); // Example usage.
+ */
+ this.getPackages = function(handler) {
+ // TODO handle getPackages() for specified Agent.
+ return getResource("/console/packages", handler);
+ };
+
+ /**
+ * Gets a List of SchemaClassId for all available Schema.
+ * @param handler a callback method to handle the asynchronously delivered response.
+ * the data passed to the handler is a list of all available classes as a JSON array of SchemaClassId.
+ * @return returns the jQuery XHR object. See getObjects() documentation for more details on why.
+ *
+ * _console.getClasses(function(data) {console.log(data)}); // Example usage.
+ */
+ this.getClasses = function(handler) {
+ // TODO handle getClasses() for specified Agent
+ return getResource("/console/classes", handler);
+ };
+
+ /**
+ * TODO
+ * getSchema() - should be easy as the REST API supports it.
+ * createSubscription() - harder as the REST API doesn't yet support it.
+ * refreshSubscription() - harder as the REST API doesn't yet support it.
+ * cancelSubscription() - harder as the REST API doesn't yet support it.
+ */
+};
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/ui/config.js b/qpid/tools/src/java/bin/qpid-web/web/ui/config.js
new file mode 100644
index 0000000000..c847d2e0c3
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/ui/config.js
@@ -0,0 +1,15 @@
+/**
+ * This file allows the initial set of Console Connections to be configured and delivered to the client.
+ * The format is as a JSON array of JSON objects containing a url property and optional name, connectionOptions and
+ * disableEvents properties. The connectionOptions property has a value that is itself a JSON object containing
+ * the connectionOptions supported by the qpid::messaging API.
+ */
+/*
+// Example Console Connection Configuration.
+qmfui.Console.consoleConnections = [
+ {name: "default", url: ""},
+ {name: "localhost", url: "localhost:5672"},
+ {name: "wildcard", url: "anonymous/@0.0.0.0:5672", connectionOptions: {sasl_mechs:"ANONYMOUS"}, disableEvents: true}
+];
+*/
+
diff --git a/qpid/tools/src/java/bin/qpid-web/web/ui/qmf.html b/qpid/tools/src/java/bin/qpid-web/web/ui/qmf.html
new file mode 100644
index 0000000000..b8115ea31d
--- /dev/null
+++ b/qpid/tools/src/java/bin/qpid-web/web/ui/qmf.html
@@ -0,0 +1,1292 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>QMF Console</title>
+ <link rel="stylesheet" type="text/css" href="/itablet/css/itablet.css"/>
+ <link rel="stylesheet" type="text/css" href="/qmf-ui/css/qmf.css"/>
+<!--[if IE 9]>
+ <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie9.css" />
+<![endif]-->
+<!--[if (lte IE 8) & (gt IE 6)]>
+ <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie8.css" />
+<![endif]-->
+<!--[if IE 7]>
+ <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie7.css" />
+<![endif]-->
+<!--[if lte IE 6]>
+ <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie6.css" />
+<![endif]-->
+
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+
+ <!-- Changes the logical window size used when displaying a page on iOS. -->
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
+
+ <!-- Sets whether a web application runs in full-screen mode. -->
+ <meta name="apple-mobile-web-app-capable" content="yes"/>
+ <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
+
+ <!-- Sets home screen icon. -->
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
+
+
+ <!-- Sets home screen icon. -->
+<!--
+ <link rel="apple-touch-startup-image" href="/startup-landscape.png" />
+-->
+
+ <script src="/itablet/scripts/jquery.js"></script>
+ <script src="/itablet/scripts/iscroll.js"></script>
+ <script src="/itablet/scripts/itablet.js"></script>
+ <script src="/qpid/scripts/qpid.js"></script>
+ <script src="/qmf-ui/scripts/qmf-ui.js"></script>
+ <script src="/ui/config.js"></script>
+<!--[if lte IE 8]>
+ <script type="text/javascript" src="/qmf-ui/scripts/excanvas.js"></script>
+<![endif]-->
+
+</head>
+
+
+<body>
+
+<!-- display simple splash screen as app loads -->
+<div id="splash">
+ <div class="logo">
+ <div class="loading">
+ </div>
+ </div>
+</div> <!-- End of splash -->
+
+<!-- The blocks provide banner style displays when an error occurs -->
+<div id="resource-deleted" class="alert">Resource Deleted</div>
+<div id="broker-disconnected" class="alert">Broker Disconnected</div>
+<div id="restapi-disconnected" class="alert">RestAPI Disconnected</div>
+<div id="failed-to-connect" class="alert">Failed to Connect</div>
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Menu/Sidebar -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="menu" class="sidebar">
+ <div class="header">
+ <h1>QMF Console</h1>
+ </div>
+
+ <div id="sidebar-scroller" class="scroll-area">
+ <ul class="contents">
+ <li id="settings-tab" class="icon"><a class="settings" href="#settings">Settings</a></li>
+ <li id="broker-tab" class="icon"><a class="brokers" href="#broker">Broker</a></li>
+ <li id="connections-tab" class="icon"><a class="connections" href="#connections">Connections</a></li>
+ <li id="exchanges-tab" class="icon"><a class="exchanges" href="#exchanges">Exchanges</a></li>
+ <li id="queues-tab" class="icon"><a class="queues" href="#queues">Queues</a></li>
+<!-- TODO add link/bridge features a la qpid-route
+ <li id="links-tab" class="icon"><a class="links" href="#links">Links</a></li>
+ <li id="route-topology-tab" class="icon"><a class="route-topology" href="#route-topology">Route Topology</a></li>
+-->
+ <li id="events-tab" class="icon"><a class="events" href="#events">Events</a></li>
+ </ul>
+ </div>
+</div>
+
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Settings -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="settings" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Settings</h1>
+ </div>
+
+ <div id="settings-scroller" class="scroll-area">
+ <div class="page">
+
+ <ul id="settings-add-console" class="list">
+ <li class="pop"><a href="#add-console-connection">Add QMF Console Connection</a></li>
+ </ul>
+
+ <h1>Available Brokers</h1>
+ <ul id="qmf-console-selector" class="list">
+ <li class="arrow">
+ <label for="qmf-console0">default</label>
+ <input type="radio" id="qmf-console0" name="qmf-console-selector" checked />
+ <a href="#selected-qmf-console-connection"></a>
+ </li>
+ </ul>
+ <p class="note">Note that selecting a new Broker Connection will clear statistics/graphs.</p>
+
+ <ul class="list">
+ <li>
+ <label for="settings-hide-qmf-objects">Hide QMF Objects</label>
+ <input type="checkbox" id="settings-hide-qmf-objects" />
+ </li>
+ </ul>
+ <p class="note">Hide Exchanges and Queues that relate to QMF.</p>
+
+ <div id="settings-hide-details-container">
+ <ul class="list">
+ <li>
+ <label for="settings-hide-details">Hide Details</label>
+ <input type="checkbox" id="settings-hide-details" checked />
+ </li>
+ </ul>
+ </div>
+ <p class="note">Hide Flow to Disk & Dequeue Details.</p>
+ </div> <!-- End of page -->
+ </div> <!-- End of settings-scroller -->
+</div> <!-- End of settings -->
+
+<div id="selected-qmf-console-connection" class="main">
+ <div class="header">
+ <a class="back button" href="#">Settings</a>
+ <h1>QMF Console Connection</h1>
+
+ <span class="toolbar">
+ <a class="delete" href="#"></a>
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="selected-qmf-console-connection-scroller" class="scroll-area">
+ <div class="page">
+ <ul class="list">
+ <li id="selected-qmf-console-connection-url"><a href="#">URL<p>url</p></a></li>
+ <li id="selected-qmf-console-connection-name"><a href="#">Name<p>name</p></a></li>
+ <li id="selected-qmf-console-connection-events-disabled"><a href="#">Events Disabled<p>false</p></a></li>
+ </ul>
+ <p id="selected-qmf-console-connection-default-info" class="note nopadding">A default URL means that the Connection URL configured on the QpidRestAPI server is being used.</p>
+
+ <div id="selected-qmf-console-connection-connection-options">
+ <h1>Connection Options</h1>
+ <ul class="list">
+ <li><textarea readonly></textarea></li>
+ </ul>
+ </div>
+ </div> <!-- End of page -->
+ </div> <!-- End of selected-qmf-console-connection-scroller -->
+</div> <!-- End of selected-qmf-console-connection -->
+
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Broker Information -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="broker" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Broker</h1>
+ </div>
+
+ <div id="broker-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="broker-list" class="list">
+ <li class><a href="#">Broker row 1</a></li>
+ </ul>
+
+ <div id="broker-msgio-container">
+ <h1>Message Input/Output</h1>
+ <ul id="broker-msgio" class="list">
+ <li><a href="#">Broker row 1</a></li>
+ </ul>
+ </div>
+
+ <div id="broker-byteio-container">
+ <h1>Byte Input/Output</h1>
+ <ul id="broker-byteio" class="list">
+ <li><a href="#">Broker row 1</a></li>
+ </ul>
+ </div>
+
+ <div id="broker-flow-to-disk-container">
+ <h1>Flow to Disk</h1>
+ <ul id="broker-flow-to-disk" class="list">
+ <li><a href="#">Broker row 1</a></li>
+ </ul>
+ </div>
+
+ <div id="broker-dequeue-container">
+ <h1>Dequeue Details</h1>
+ <ul id="broker-dequeue" class="list">
+ <li><a href="#">Broker row 1</a></li>
+ </ul>
+ </div>
+
+ <h1>Set Log Level</h1>
+ <ul id="broker-log-level" class="list">
+ <li>
+ <label for="broker-log-normal">Normal</label>
+ <input type="radio" id="broker-log-normal" name="broker-log-level" value="normal" checked />
+ </li>
+ <li>
+ <label for="broker-log-debug">Debug</label>
+ <input type="radio" id="broker-log-debug" name="broker-log-level" value="debug"/>
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of broker-scroller -->
+</div> <!-- End of broker -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Connection Information -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="connections" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Connections</h1>
+ </div>
+
+ <div id="connections-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="connections-list" class="list">
+ <li class="arrow"><a href="#selected-connection">Dummy Connection</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of connections-scroller -->
+</div> <!-- End of connections -->
+
+<div id="selected-connection" class="main">
+ <div class="header">
+ <a class="back button" href="#">Connect...</a>
+ <h1>Selected Connection</h1>
+
+ <span class="toolbar">
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="selected-connection-scroller" class="scroll-area">
+ <div class="page">
+ <h1 class="first">Message Input/Output</h1>
+ <ul id="selected-connection-msgio" class="list">
+ <li class="arrow"><a href="#graphs">Selected Connection row 1</a></li>
+ </ul>
+
+ <h1>Byte Input/Output</h1>
+ <ul id="selected-connection-byteio" class="list">
+ <li><a href="#">Selected Connection row 1</a></li>
+ </ul>
+
+ <h1>Frame Input/Output</h1>
+ <ul id="selected-connection-frameio" class="list">
+ <li><a href="#">Selected Connection row 1</a></li>
+ </ul>
+
+ <h1>General</h1>
+ <ul id="selected-connection-general" class="list">
+ <li><a href="#">Selected Connection row 1</a></li>
+ </ul>
+
+ <h1>Subscribed Sessions</h1>
+ <ul id="selected-connection-subscribed-sessions" class="list">
+ <li class="arrow"><a href="#connection-sessions">Selected Connection Session 1</a></li>
+ </ul>
+
+ <h1>Unsubscribed Sessions</h1>
+ <ul id="selected-connection-unsubscribed-sessions" class="list">
+ <li><a href="#connection-sessions">Selected Connection Session 1</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of selected-connection-scroller -->
+</div> <!-- End of selected-connection -->
+
+<div id="connection-subscriptions" class="main">
+ <div class="header">
+ <a class="back button" href="#">Connect...</a>
+ <h1>Connection Subscriptions</h1>
+
+ <span class="toolbar">
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="connection-subscriptions-scroller" class="scroll-area">
+ <div class="page">
+ <h1>Subscription</h1>
+ <ul id="connection-subscriptions-list" class="list">
+ <li><a href="#">Selected Subscription row 1</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of connection-subscriptions-scroller -->
+</div> <!-- End of connection-subscriptions -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Exchange Information -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="exchanges" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Exchanges</h1>
+ </div>
+
+ <div id="exchanges-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="exchanges-add-exchange" class="list">
+ <li class="pop"><a href="#add-exchange">Add Exchange</a></li>
+ </ul>
+ <p/>
+
+ <ul id="exchanges-list" class="list">
+ <li class="arrow"><a href="#selected-exchange">Dummy Exchange</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of exchanges-scroller -->
+</div> <!-- End of exchanges -->
+
+<div id="selected-exchange" class="main">
+ <div class="header">
+ <a class="back button" href="#">Exchan...</a>
+ <h1>Selected Exchange</h1>
+
+ <span class="toolbar">
+ <a class="delete" href="#"></a>
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="selected-exchange-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="selected-exchange-bindings" class="list">
+ <li class="arrow"><a href="#bindings">Bindings</a></li>
+ </ul>
+
+ <h1>Message Input/Output</h1>
+ <ul id="selected-exchange-msgio" class="list">
+ <li class="arrow" ><a href="#graphs">Selected Exchange row 1</a></li>
+ </ul>
+
+ <h1>Byte Input/Output</h1>
+ <ul id="selected-exchange-byteio" class="list">
+ <li><a href="#">Selected Exchange row 1</a></li>
+ </ul>
+
+ <h1>General</h1>
+ <ul id="selected-exchange-general" class="list">
+ <li><a href="#">Selected Exchange row 1</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of selected-exchange-scroller -->
+</div> <!-- End of selected-exchange -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Queue Information -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="queues" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Queues</h1>
+ </div>
+
+ <div id="queues-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="queues-add-queue" class="list">
+ <li class="pop"><a href="#add-queue">Add Queue</a></li>
+ </ul>
+ <p/>
+
+ <ul id="queues-list" class="list">
+ <li class="arrow"><a href="#selected-queue">Dummy Queue</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of queues-scroller -->
+</div> <!-- End of queues -->
+
+<div id="selected-queue" class="main">
+ <div class="header">
+ <a class="back button" href="#">Queues</a>
+ <h1>Selected Queue</h1>
+
+ <span class="toolbar">
+ <a class="delete" href="#"></a>
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="selected-queue-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="selected-queue-bindings" class="list">
+ <li class="arrow"><a href="#bindings">Bindings</a></li>
+ </ul>
+
+ <h1>Message Input/Output</h1>
+ <ul id="selected-queue-msgio" class="list">
+ <li class="arrow"><a href="#graphs">Selected Queue row 1</a></li>
+ </ul>
+
+ <h1>Byte Input/Output</h1>
+ <ul id="selected-queue-byteio" class="list">
+ <li><a href="#">Selected Queue row 1</a></li>
+ </ul>
+
+ <h1>General</h1>
+ <ul id="selected-queue-general" class="list">
+ <li><a href="#">Selected Queue row 1</a></li>
+ </ul>
+
+ <div id="selected-queue-flow-to-disk-container">
+ <h1>Flow to Disk</h1>
+ <ul id="selected-queue-flow-to-disk" class="list">
+ <li><a href="#">Selected Queue row 1</a></li>
+ </ul>
+ </div>
+
+ <div id="selected-queue-dequeue-container">
+ <h1>Dequeue Details</h1>
+ <ul id="selected-queue-dequeue" class="list">
+ <li><a href="#">Selected Queue row 1</a></li>
+ </ul>
+ </div>
+
+ <h1>Subscriptions</h1>
+ <ul id="selected-queue-subscriptions" class="list">
+ <li class="arrow"><a href="#queue-subscriptions">Selected Queue Subscription 1</a></li>
+ </ul>
+
+ <!-- This wrapper div makes it easy to hide these admin functions on QMF queues -->
+ <div id="selected-queue-admin-wrapper">
+ <h1>Admin</h1>
+ <ul id="selected-queue-admin" class="list">
+ <li class="arrow pop"><a href="#purge-queue">Purge</a></li>
+ <li class="arrow pop"><a href="#reroute-messages">Reroute Messages</a></li>
+ <li class="arrow pop"><a href="#move-messages">Move Messages</a></li>
+ </ul>
+ </div>
+ </div> <!-- End of page -->
+ </div> <!-- End of selected-queue-scroller -->
+</div> <!-- End of selected-queue -->
+
+<div id="queue-subscriptions" class="main">
+ <div class="header">
+ <a class="back button" href="#">Queue</a>
+ <h1>Selected Subscription</h1>
+
+ <span class="toolbar">
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="queue-subscriptions-scroller" class="scroll-area">
+ <div class="page">
+ <h1 class="first">Connection</h1>
+ <ul id="queue-subscriptions-connection" class="list">
+ <li class="arrow"><a href="#">Selected Subscription row 1</a></li>
+ </ul>
+
+ <h1>Session</h1>
+ <ul id="queue-subscriptions-session" class="list">
+ <li><a href="#">Selected Subscription row 1</a></li>
+ </ul>
+
+ <h1>Subscription</h1>
+ <ul id="queue-subscriptions-subscription" class="list">
+ <li><a href="#">Selected Subscription row 1</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of queue-subscriptions-scroller -->
+</div> <!-- End of queue-subscriptions -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="bindings" class="main">
+ <div class="header">
+ <a class="back button" href="#">Queue</a>
+ <h1>Bindings</h1>
+
+ <span class="toolbar">
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="bindings-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="bindings-add-binding" class="list">
+ <li class="pop"><a href="#add-binding">Add Binding</a></li>
+ </ul>
+
+ <h1 class="first">Bindings</h1>
+ <ul id="bindings-list" class="list">
+ <li class="arrow"><a href="#">Binding 1</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of bindings-scroller -->
+</div> <!-- End of bindings -->
+
+<div id="graphs" class="main">
+ <div class="header">
+ <a class="back button" href="#">Back</a>
+ <h1>Graphs</h1>
+
+ <span class="toolbar">
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="graphs-scroller" class="scroll-area">
+ <div class="page">
+
+ <ul id="graphs-time-selector" class="list">
+ <li>
+ <label>10 minutes</label><input type="radio" value="tenMinutes" name="graphs-time-selector" checked />
+ </li>
+ <li>
+ <label>1 hour</label><input type="radio" value="oneHour" name="graphs-time-selector" />
+ </li>
+ <li>
+ <label>1 day</label><input type="radio" value="oneDay" name="graphs-time-selector" />
+ </li>
+ </ul>
+
+ <h1>Graph Title</h1>
+ <canvas id="graphs-canvas">
+ Your browser does not support the canvas element.
+ </canvas>
+ </div> <!-- End of page -->
+ </div> <!-- End of graphs-scroller -->
+</div> <!-- End of graphs -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="links" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Links</h1>
+ </div>
+
+ <div id="links-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="links-list" class="list">
+ <li class="arrow"><a href="#">Not Yet Supported</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of links-scroller -->
+</div> <!-- End of links -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="route-topology" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Route Topology</h1>
+ </div>
+
+ <div id="route-topology-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="route-topology-list" class="list">
+ <li class="arrow"><a href="#">Not Yet Supported</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of route-topology-scroller -->
+</div> <!-- End of route-topology -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Asynchronous Broker Events -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<div id="events" class="main">
+ <div class="header">
+ <a class="menu back button" href="#">QMF Con...</a>
+ <h1>Events</h1>
+ </div>
+
+ <div id="events-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="events-list" class="list">
+ <li class="grey"><a href="#">There are currently no events available</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of events-scroller -->
+</div> <!-- End of events -->
+
+<div id="selected-event" class="main">
+ <div class="header">
+ <a class="back button" href="#">Events</a>
+ <h1>Selected Event</h1>
+
+ <span class="toolbar">
+ <a class="menu home" href="#"></a>
+ </span>
+ </div>
+
+ <div id="selected-event-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="selected-event-list" class="list">
+ <li><a href="#">Selected Event row 1</a></li>
+ </ul>
+ <p/>
+ <ul id="selected-event-values" class="list">
+ <li><a href="#">Selected Event row 1</a></li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of selected-event-scroller -->
+</div> <!-- End of selected-event -->
+
+
+
+<!----------------------------------------------------------------------------------------------------------------->
+<!-- Popup Form Windows -->
+<!----------------------------------------------------------------------------------------------------------------->
+
+<!--
+<div class="popup-window"> and <div class="popup-container"> act as the container elements for all popup windows
+these are used to enable a semi-transparent "smoked glass" background behind the actual popup.
+-->
+<div class="popup-window">
+ <div class="popup-container">
+
+
+ <div id="add-console-connection" class="popup">
+ <div class="header">
+ <a class="cancel button" href="#">Cancel</a>
+ <h1>Add QMF Console Connection</h1>
+ <a class="blue right button" href="#">Done</a>
+ </div>
+
+ <div id="add-console-connection-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li>
+ <label for="console-url">URL</label>
+ <input type="text" id="console-url" placeholder="guest/guest@host:5672" required />
+ </li>
+ <li>
+ <label for="console-name">Name</label>
+ <input type="text" id="console-name" placeholder="Operational Broker" />
+ </li>
+ </ul>
+ <p class="note">URL may be any AMQP URL format, Name is a name used to identify the Broker.</p>
+
+ <ul class="list">
+ <li>
+ <label for="console-disable-events">Disable Events</label>
+ <input type="checkbox" id="console-disable-events" />
+ </li>
+ </ul>
+ <p class="note nopadding">Disable QMF2 Events, use polling to update state instead.</p>
+
+ <h1>Connection Options</h1>
+ <ul id="add-connection-options" class="list">
+ <li>
+ <textarea placeholder='{"sasl_mechanisms": "GSSAPI", "protocol": "ssl"}'></textarea>
+ </li>
+ </ul>
+ <p class="note">Connection Options are not required for most QMF Connections, but may be needed in some authentication edge cases.</p>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-console-connection-scroller -->
+ </div> <!-- End of add-console-connection -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+ <div id="add-exchange" class="popup">
+ <div class="header">
+ <a class="cancel button" href="#">Cancel</a>
+ <h1>Add Exchange</h1>
+ <a class="blue right button" href="#">Done</a>
+ </div>
+
+ <div id="add-exchange-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li>
+ <label for="exchange-name">Name</label>
+ <input type="text" id="exchange-name" placeholder="Exchange Name" required />
+ </li>
+ </ul>
+ <p/>
+ <ul class="list">
+ <li id="add-exchange-exchange-type" class="arrow">
+ <a href="#exchange-type">Exchange Type<p>direct</p></a>
+ </li>
+ <li class="arrow"><a href="#add-exchange-additional">Additional Options</a></li>
+ </ul>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-exchange-scroller -->
+ </div> <!-- End of add-exchange -->
+
+ <div id="exchange-type" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Exc...</a>
+ <h1>Exchange Type</h1>
+ </div>
+
+ <div id="exchange-type-scroller" class="scroll-area">
+ <div class="page">
+ <ul class="list">
+ <li>
+ <label for="direct">direct</label>
+ <input type="radio" id="direct" name="exchange-type" value="direct" checked />
+ </li>
+ <li>
+ <label for="fanout">fanout</label>
+ <input type="radio" id="fanout" name="exchange-type" value="fanout" />
+ </li>
+ <li>
+ <label for="topic">topic</label>
+ <input type="radio" id="topic" name="exchange-type" value="topic" />
+ </li>
+ <li>
+ <label for="headers">headers</label>
+ <input type="radio" id="headers" name="exchange-type" value="headers" />
+ </li>
+ <li>
+ <label for="xml">xml</label>
+ <input type="radio" id="xml" name="exchange-type" value="xml" />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of exchange-type-scroller -->
+ </div> <!-- End of exchange-type -->
+
+ <div id="add-exchange-additional" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Exc...</a>
+ <h1>Additional Options</h1>
+ </div>
+
+ <div id="add-exchange-additional-scroller" class="scroll-area">
+ <div class="page">
+ <h1 class="first">Alternate Exchange</h1>
+ <ul class="list">
+ <li id="add-exchange-additional-alternate-exchange-name" class="arrow">
+ <a href="#add-exchange-select-alternate-exchange">Exchange<p>None (default)</p></a>
+ </li>
+ </ul>
+ <p class="note">Route messages here if this exchange is unable to route them elsewhere.</p>
+
+ <ul class="list">
+ <li>
+ <label for="exchange-durable">Durable</label>
+ <input type="checkbox" id="exchange-durable"/>
+ </li>
+ <li>
+ <label for="sequence">Sequence Number</label>
+ <input type="checkbox" id="sequence"/>
+ </li>
+ <li>
+ <label for="ive">Initial Value Exchange</label>
+ <input type="checkbox" id="ive"/>
+ </li>
+ </ul>
+ <p class="note">An Initial Value Exchange will keep a reference to the last message forwarded and enqueue that message to newly bound queues.</p>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-exchange-additional-scroller -->
+ </div> <!-- End of add-exchange-additional -->
+
+ <div id="add-exchange-select-alternate-exchange" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Additio...</a>
+ <h1>Alternate Exchange</h1>
+ </div>
+
+ <div id="add-exchange-select-alternate-exchange-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="add-exchange-select-alternate-exchange-list" class="list">
+ <li>
+ <label for="add-exchange-select-alternate-exchange-exchangeNone">None (default)</label>
+ <input type="radio" id="add-exchange-select-alternate-exchange-exchangeNone" name="add-exchange-select-alternate-exchange" value="None (default)" checked />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-exchange-select-alternate-exchange-scroller -->
+ </div> <!-- End of add-exchange-select-alternate-exchange -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+ <div id="add-queue" class="popup">
+ <div class="header">
+ <a class="cancel button" href="#">Cancel</a>
+ <h1>Add Queue</h1>
+ <a class="blue right button" href="#">Done</a>
+ </div>
+
+ <div id="add-queue-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li>
+ <label for="queue-name">Name</label>
+ <input type="text" id="queue-name" placeholder="Queue Name" required />
+ </li>
+ </ul>
+
+ <h1>Maximum In-memory Queue Size</h1>
+ <ul class="list">
+ <li>
+ <label for="max-queue-size">Max Size</label>
+ <input type="text" id="max-queue-size" placeholder="Size (bytes) [K|M|G]"/>
+ </li>
+ <li>
+ <label for="max-queue-count">Max Count</label>
+ <input type="text" id="max-queue-count" placeholder="Size (messages)"/>
+ </li>
+ </ul>
+ <p class="note">Queue sizes are optional, if not specified broker defaults will be used.</p>
+
+ <ul class="list">
+ <li id="add-queue-limit-policy" class="arrow">
+ <a href="#limit-policy">Limit Policy<p>None (default)</p></a>
+ </li>
+ <li id="add-queue-ordering-policy" class="arrow">
+ <a href="#ordering-policy">Order Policy<p>Fifo (default)</p></a>
+ </li>
+ <li id="add-queue-generate-queue-events" class="arrow">
+ <a href="#generate-queue-events">Event Policy<p>Off (default)</p></a>
+ </li>
+ <li class="arrow"><a href="#add-queue-additional">Additional Options</a></li>
+ </ul>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-queue-scroller -->
+ </div> <!-- End of add-queue -->
+
+ <div id="limit-policy" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Queue</a>
+ <h1>Limit Policy</h1>
+ </div>
+
+ <div id="limit-policy-scroller" class="scroll-area">
+ <div class="page">
+ <ul class="list">
+ <li>
+ <label for="none">None (default)</label>
+ <input type="radio" id="none" name="limit-policy" value="none" checked />
+ </li>
+ <li>
+ <label for="reject">Reject</label>
+ <input type="radio" id="reject" name="limit-policy" value="reject" />
+ </li>
+ <li>
+ <label for="flow-to-disc">Flow to Disc</label>
+ <input type="radio" id="flow-to-disc" name="limit-policy" value="flow_to_disk" />
+ </li>
+ <li>
+ <label for="ring">Ring</label>
+ <input type="radio" id="ring" name="limit-policy" value="ring" />
+ </li>
+ <li>
+ <label for="ring-strict">Ring Strict</label>
+ <input type="radio" id="ring-strict" name="limit-policy" value="ring_strict" />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of limit-policy-scroller -->
+ </div> <!-- End of limit-policy -->
+
+ <div id="ordering-policy" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Queue</a>
+ <h1>Order Policy</h1>
+ </div>
+
+ <div id="ordering-policy-scroller" class="scroll-area">
+ <div class="page">
+ <ul class="list">
+ <li>
+ <label for="fifo">Fifo (default)</label>
+ <input type="radio" id="fifo" name="ordering-policy" value="fifo" checked />
+ </li>
+ <li>
+ <label for="lvq">LVQ</label>
+ <input type="radio" id="lvq" name="ordering-policy" value="lvq" />
+ </li>
+ <li>
+ <label for="lvq-no-browse">LVQ No Browse</label>
+ <input type="radio" id="lvq-no-browse" name="ordering-policy" value="lvq-no-browse" />
+ </li>
+ </ul>
+ <p class="note">Fifo or Last Value Queue.</p>
+ </div> <!-- End of page -->
+ </div> <!-- End of ordering-policy-scroller -->
+ </div> <!-- End of ordering-policy -->
+
+ <div id="generate-queue-events" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Queue</a>
+ <h1>Event Policy</h1>
+ </div>
+
+ <div id="generate-queue-events-scroller" class="scroll-area">
+ <div class="page">
+ <ul class="list">
+ <li>
+ <label for="generate-no-events">Off (default)</label>
+ <input type="radio" id="generate-no-events" name="generate-queue-events" value="" checked />
+ </li>
+ <li>
+ <label for="generate-enqueue-events">Enqueue</label>
+ <input type="radio" id="generate-enqueue-events" name="generate-queue-events" value="1" />
+ </li>
+ <li>
+ <label for="generate-enqueue-dequeue-events">Enqueue & Dequeue</label>
+ <input type="radio" id="generate-enqueue-dequeue-events" name="generate-queue-events" value="2" />
+ </li>
+ </ul>
+ <p class="note">Generate an event that can be processed by registered listeners (e.g. for replication).</p>
+ </div> <!-- End of page -->
+ </div> <!-- End of generate-queue-events-scroller -->
+ </div> <!-- End of generate-queue-events -->
+
+ <div id="add-queue-additional" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Que...</a>
+ <h1>Additional Options</h1>
+ </div>
+
+ <div id="add-queue-additional-scroller" class="scroll-area">
+ <div class="page">
+ <h1 class="first">Alternate Exchange</h1>
+ <ul class="list">
+ <li id="add-queue-additional-alternate-exchange-name" class="arrow">
+ <a href="#add-queue-select-alternate-exchange">Exchange<p>None (default)</p></a>
+ </li>
+ </ul>
+ <p class="note">Route messages here if rejected by a subscriber or orphaned by queue deletion.</p>
+
+ <ul id="add-queue-additional-durable-list" class="list">
+ <li>
+ <label for="queue-durable">Durable</label>
+ <input type="checkbox" id="queue-durable"/>
+ </li>
+ <li>
+ <label for="queue-cluster-durable">Cluster Durable</label>
+ <input type="checkbox" id="queue-cluster-durable"/>
+ </li>
+ <li>
+ <label for="file-size">File Size</label>
+ <input type="text" id="file-size" placeholder="24"/>
+ </li>
+ <li>
+ <label for="file-count">File Count</label>
+ <input type="text" id="file-count" placeholder="8"/>
+ </li>
+ </ul>
+
+ <ul id="add-queue-additional-hidden-list" class="list">
+ hidden list
+ </ul>
+
+ <p id="add-queue-additional-journal-note" class="note nopadding">
+ Journal sizes are optional, if not specified defaults will be used.
+ </p>
+
+ <h1>Flow Control</h1>
+ <ul class="list">
+ <li>
+ <label for="flow-stop-size">Stop Size</label>
+ <input type="text" id="flow-stop-size" placeholder="0 (bytes)"/>
+ </li>
+ <li>
+ <label for="flow-stop-count">Stop Count</label>
+ <input type="text" id="flow-stop-count" placeholder="0 (messages)"/>
+ </li>
+ <li>
+ <label for="flow-resume-size">Start Size</label>
+ <input type="text" id="flow-resume-size" placeholder="0 (bytes)"/>
+ </li>
+ <li>
+ <label for="flow-resume-count">Start Count</label>
+ <input type="text" id="flow-resume-count" placeholder="0 (messages)"/>
+ </li>
+ </ul>
+ <p class="note">When one of the stop thresholds are exceeded producer flow control is enabled until the flow drops below one of the start thresholds</p>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-queue-additional-scroller -->
+ </div> <!-- End of add-queue-additional -->
+
+ <div id="add-queue-select-alternate-exchange" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Additio...</a>
+ <h1>Alternate Exchange</h1>
+ </div>
+
+ <div id="add-queue-select-alternate-exchange-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="add-queue-select-alternate-exchange-list" class="list">
+ <li>
+ <label for="add-queue-select-alternate-exchange-exchangeNone">None (default)</label>
+ <input type="radio" id="add-queue-select-alternate-exchange-exchangeNone" name="add-queue-select-alternate-exchange" value="None (default)" checked />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-queue-select-alternate-exchange-scroller -->
+ </div> <!-- End of add-exchange-select-alternate-exchange -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+ <div id="purge-queue" class="popup">
+ <div class="header">
+ <a class="cancel button" href="#">Cancel</a>
+ <h1>Purge Queue</h1>
+ <a class="blue right button" href="#">Done</a>
+ </div>
+
+ <div id="purge-queue-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li>
+ <label for="purge-queue-request-number">Number</label>
+ <input type="text" id="purge-queue-request-number" placeholder="Message Count" />
+ </li>
+ </ul>
+ <p class="note">Discards all or some messages from this queue. A value of 0 (default) discards all messages otherwise use the specified number.</p>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of purge-queue-scroller -->
+ </div> <!-- End of purge-queue -->
+
+
+ <div id="reroute-messages" class="popup">
+ <div class="header">
+ <a class="cancel button" href="#">Cancel</a>
+ <h1>Reroute Messages</h1>
+ <a class="blue right button" href="#">Done</a>
+ </div>
+
+ <div id="reroute-messages-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li>
+ <label for="reroute-messages-request-number">Number</label>
+ <input type="text" id="reroute-messages-request-number" placeholder="Message Count" />
+ </li>
+ </ul>
+ <p class="note">Remove all or some messages from this queue and route them to an exchange. A value of 0 (default) reroutes all messages otherwise use the specified number.</p>
+
+ <ul class="list">
+ <li>
+ <label for="reroute-messages-use-alternate-exchange">Alternate Exchange</label>
+ <input type="checkbox" id="reroute-messages-use-alternate-exchange"/>
+ </li>
+ </ul>
+ <p class="note">Use the queue's configured alternate exchange.</p>
+ <!-- reroute-messages-use-selected-exchange div is used to show/hide the following -->
+ <ul id="reroute-messages-use-selected-exchange" class="list">
+ <li id="reroute-messages-exchange-name" class="arrow">
+ <a href="#reroute-messages-select-exchange">Exchange<p>None (default)</p></a>
+ </li>
+ </ul>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of reroute-messages-scroller -->
+ </div> <!-- End of reroute-messages -->
+
+
+ <div id="reroute-messages-select-exchange" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Reroute...</a>
+ <h1>Select Exchange</h1>
+ </div>
+
+ <div id="reroute-messages-select-exchange-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="reroute-messages-select-exchange-list" class="list">
+ <li>
+ <label for="reroute-messages-exchangeNone">None (default)</label>
+ <input type="radio" id="reroute-messages-exchangeNone" name="reroute-messages-select-exchange" value="None (default)" checked />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of reroute-messages-select-exchange-scroller -->
+ </div> <!-- End of reroute-messages-select-exchange -->
+
+
+ <div id="move-messages" class="popup">
+ <div class="header">
+ <a class="cancel button" href="#">Cancel</a>
+ <h1>Move Messages</h1>
+ <a class="blue right button" href="#">Done</a>
+ </div>
+
+ <div id="move-messages-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li>
+ <label for="move-messages-request-number">Number</label>
+ <input type="text" id="move-messages-request-number" placeholder="Message Count" />
+ </li>
+ </ul>
+ <p class="note">Move messages from this queue to another. A value of 0 (default) moves all messages otherwise use the specified number.</p>
+
+ <ul class="list">
+ <li id="move-messages-queue-name" class="arrow">
+ <a href="#move-messages-select-queue">Queue<p>None (default)</p></a>
+ </li>
+ </ul>
+ <p class="note">Destination Queue.</p>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of move-messages-scroller -->
+ </div> <!-- End of move-messages -->
+
+ <div id="move-messages-select-queue" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Move Me...</a>
+ <h1>Select Queue</h1>
+ </div>
+
+ <div id="move-messages-select-queue-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="move-messages-select-queue-list" class="list">
+ <li>
+ <label for="move-messages-select-queueNone">None (default)</label>
+ <input type="radio" id="move-messages-select-queueNone" name="move-messages-select-queue" value="None (default)" checked />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of move-messages-select-queue-scroller -->
+ </div> <!-- End of move-messages-select-queue -->
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+ <div id="add-binding" class="popup">
+ <div class="header">
+ <a class="cancel button" href="#">Cancel</a>
+ <h1>Add Binding</h1>
+ <a class="blue right button" href="#">Done</a>
+ </div>
+
+ <div id="add-binding-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li id="add-binding-exchange-name" class="arrow">
+ <a href="#add-binding-select-exchange">Exchange<p>None (default)</p></a>
+ </li>
+ <li id="add-binding-queue-name" class="arrow">
+ <a href="#add-binding-select-queue">Queue<p>None (default)</p></a>
+ </li>
+ <li>
+ <label for="add-binding-key-name">Key</label>
+ <input type="text" id="add-binding-key-name" placeholder="Binding Key"/>
+ </li>
+ </ul>
+ <p class="note nopadding">
+ Key is optional, but without it the Binding cannot be explicitly deleted.
+ </p>
+
+ <h1>Headers</h1>
+ <ul id="add-headers-binding" class="list">
+ <li id="add-headers-binding-x-match" class="arrow">
+ <a href="#x-match">Match<p>all</p></a>
+ </li>
+ <li class="arrow">
+ <a href="#add-header-match">Add...</a>
+ </li>
+ </ul>
+
+ <ul id="add-xml-binding" class="list">
+ <li>
+ <textarea placeholder="Add XQuery here"></textarea>
+ </li>
+ </ul>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-binding-scroller -->
+ </div> <!-- End of add-binding -->
+
+ <div id="add-binding-select-exchange" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Bin...</a>
+ <h1>Select Exchange</h1>
+ </div>
+
+ <div id="add-binding-select-exchange-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="add-binding-select-exchange-list" class="list">
+ <li>
+ <label for="add-binding-exchangeNone">None (default)</label>
+ <input type="radio" id="add-binding-exchangeNone" name="add-binding-select-exchange" value="None (default)" checked />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-binding-select-exchange-scroller -->
+ </div> <!-- End of add-binding-select-exchange -->
+
+ <div id="add-binding-select-queue" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Bind...</a>
+ <h1>Select Queue</h1>
+ </div>
+
+ <div id="add-binding-select-queue-scroller" class="scroll-area">
+ <div class="page">
+ <ul id="add-binding-select-queue-list" class="list">
+ <li>
+ <label for="add-binding-queueNone">None (default)</label>
+ <input type="radio" id="add-binding-queueNone" name="add-binding-select-queue" value="None (default)" checked />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-binding-select-queue-scroller -->
+ </div> <!-- End of add-binding-select-queue -->
+
+ <div id="x-match" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Binding</a>
+ <h1>Match</h1>
+ </div>
+
+ <div id="x-match-scroller" class="scroll-area">
+ <div class="page">
+ <ul class="list">
+ <li>
+ <label for="x-match-all">all</label>
+ <input type="radio" id="x-match-all" name="x-match" value="all" checked />
+ </li>
+ <li>
+ <label for="x-match-any">any</label>
+ <input type="radio" id="x-match-any" name="x-match" value="any" />
+ </li>
+ </ul>
+ </div> <!-- End of page -->
+ </div> <!-- End of x-match-scroller -->
+ </div> <!-- End of x-match -->
+
+ <div id="add-header-match" class="popup">
+ <div class="header">
+ <a class="back button" href="#">Add Bind...</a>
+ <h1>Header Match</h1>
+ <a class="blue right button" href="#">Add</a>
+ </div>
+
+ <div id="add-header-match-scroller" class="scroll-area">
+ <div class="page">
+ <form action="#">
+ <ul class="list">
+ <li>
+ <label for="header-match-key">Key</label>
+ <input type="text" id="header-match-key" placeholder="Header Name"/>
+ </li>
+ <li>
+ <label for="header-match-value">Value</label>
+ <input type="text" id="header-match-value" placeholder="Match Value"/>
+ </li>
+ </ul>
+ <p class="note">
+ Specify a Header name and a value to match the Header against.
+ </p>
+ </form>
+ </div> <!-- End of page -->
+ </div> <!-- End of add-header-match-scroller -->
+ </div> <!-- End of add-header-match -->
+
+
+ </div> <!-- End of popup-container -->
+</div> <!-- End of popup-window -->
+
+
+<!----------------------------------------------------------------------------------------------------------------->
+
+</body>
+</html>
diff --git a/qpid/tools/src/java/bin/whitelist.xml b/qpid/tools/src/java/bin/whitelist.xml
new file mode 100644
index 0000000000..5c39c50d43
--- /dev/null
+++ b/qpid/tools/src/java/bin/whitelist.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<whitelist>
+ <exchangeWhitelist>
+ <exchange>qmf.default.topic</exchange>
+ <exchange>qmf.default.direct</exchange>
+ <exchange>qpid.management</exchange>
+ <exchange>amq.direct</exchange>
+ <exchange></exchange>
+ </exchangeWhitelist>
+ <queueWhitelist>
+ <queue>testqueue1</queue>
+ </queueWhitelist>
+</whitelist>
diff --git a/qpid/tools/src/java/build.xml b/qpid/tools/src/java/build.xml
new file mode 100644
index 0000000000..1b19abd173
--- /dev/null
+++ b/qpid/tools/src/java/build.xml
@@ -0,0 +1,241 @@
+<?xml version="1.0"?>
+<!--
+ -
+ - 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.
+ -
+ -->
+
+<project name="QMF2 API Implementation" default="api" basedir=".">
+ <!-- =================================================================== -->
+ <!-- Note that this requires the QPID_HOME environment variable -->
+ <!-- to be set and it installs the plugin to $QPID_HOME/lib/plugins -->
+ <!-- =================================================================== -->
+
+ <property environment="env"/>
+ <property name="qpid.home" location="${env.QPID_HOME}"/>
+ <property name="qpid.lib" location="${qpid.home}/lib"/>
+ <property name="qpid.lib.plugins" location="${qpid.lib}/plugins"/>
+
+ <!-- =================================================================== -->
+ <!-- Builds the QMF2 and REST APIs -->
+ <!-- Use this if you have Qpid version 0.12+ as this doesn't override -->
+ <!-- the now working latest version of AMQMessageDelegate_0_10. -->
+ <!-- =================================================================== -->
+ <target name="api" depends="main-jar, restapi-jar, api-doc">
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Builds the QMF2 and REST APIs and the AMQMessageDelegate_0_10 patch.-->
+ <!-- Use this if you have a Qpid version < 0.12 as it includes the patch -->
+ <!-- for AMQMessageDelegate_0_10.java that is needed to work with older -->
+ <!-- Qpid versions. N.B. This task won't compile on later Qoid versions. -->
+ <!-- =================================================================== -->
+ <target name="api-patched" depends="main-jar, patch-jar, restapi-jar, api-doc">
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Builds the QMF2 and REST APIs plus the QMF2 Agent Plugin to enable -->
+ <!-- the Java Broker to talk QMF2. -->
+ <!-- Note that this task only compiles on Qpid Java version > 0.20 -->
+ <!-- =================================================================== -->
+ <target name="all" depends="main-jar, restapi-jar, qpid-broker-plugins-management-qmf2-jar, all-doc">
+ <mkdir dir="${qpid.lib.plugins}"/>
+
+ <copy file="build/lib/qmf2.jar" todir="${qpid.lib.plugins}"/>
+ <copy file="build/lib/qpid-broker-plugins-management-qmf2.jar" todir="${qpid.lib.plugins}"/>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the main API code -->
+ <!-- =================================================================== -->
+ <target name="main">
+ <mkdir dir="build/scratch/qmf2/classes"/>
+
+ <javac srcdir="src/main/java"
+ destdir="build/scratch/qmf2/classes"
+ debug="off"
+ deprecation="on"
+ includeantruntime="false"
+ optimize="on">
+ <classpath location="${qpid.lib}/qpid-all.jar"/>
+ </javac>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the test code -->
+ <!-- =================================================================== -->
+ <target name="test" depends="main">
+ <mkdir dir="build/scratch/qmf2/testclasses"/>
+
+ <javac srcdir="src/test/java"
+ destdir="build/scratch/qmf2/testclasses"
+ debug="off"
+ deprecation="on"
+ includeantruntime="false"
+ optimize="on">
+ <classpath>
+ <pathelement location="${qpid.lib}/qpid-all.jar"/>
+ <pathelement location="build/scratch/qmf2/classes"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the patch needed for Qpid versions older than 0.12 -->
+ <!-- =================================================================== -->
+ <target name="patch">
+ <mkdir dir="build/scratch/patch"/>
+
+ <javac srcdir="src/patch/java"
+ destdir="build/scratch/patch"
+ debug="off"
+ deprecation="on"
+ includeantruntime="false"
+ optimize="on">
+ <classpath location="${qpid.lib}/qpid-all.jar"/>
+ </javac>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the Java Broker QMF2 Agent Plugin -->
+ <!-- =================================================================== -->
+ <target name="qpid-broker-plugins-management-qmf2">
+ <mkdir dir="build/scratch/qpid-broker-plugins-management-qmf2"/>
+
+ <javac srcdir="src/qpid-broker-plugins-management-qmf2/java"
+ destdir="build/scratch/qpid-broker-plugins-management-qmf2"
+ debug="off"
+ deprecation="on"
+ includeantruntime="false"
+ optimize="on">
+ <classpath>
+ <pathelement location="${qpid.lib}/qpid-all.jar"/>
+ <pathelement location="build/scratch/qmf2/classes"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the HTTP REST API Server -->
+ <!-- =================================================================== -->
+ <target name="restapi" depends="main">
+ <mkdir dir="build/scratch/restapi"/>
+
+ <javac srcdir="src/restapi/java"
+ destdir="build/scratch/restapi"
+ debug="off"
+ deprecation="on"
+ includeantruntime="false"
+ optimize="on">
+ <classpath>
+ <pathelement location="${qpid.lib}/qpid-all.jar"/>
+ <pathelement location="build/scratch/qmf2/classes"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Generates the main jars -->
+ <!-- =================================================================== -->
+ <target name="main-jar" depends="main, test">
+ <mkdir dir="build/lib"/>
+
+ <jar destfile="build/lib/qmf2.jar" basedir="build/scratch/qmf2/classes">
+ </jar>
+
+ <jar destfile="build/lib/qmf2test.jar" basedir="build/scratch/qmf2/testclasses">
+ </jar>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Generates the jar for the patch needed by Qpid versions < 0.12 -->
+ <!-- =================================================================== -->
+ <target name="patch-jar" depends="patch">
+ <mkdir dir="build/lib"/>
+ <jar destfile="build/lib/qpid-client-patch.jar" basedir="build/scratch/patch">
+ </jar>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Generates the jar for the Java Broker QMF2 Agent Plugin -->
+ <!-- =================================================================== -->
+ <target name="qpid-broker-plugins-management-qmf2-jar" depends="qpid-broker-plugins-management-qmf2">
+ <mkdir dir="build/lib"/>
+ <jar destfile="build/lib/qpid-broker-plugins-management-qmf2.jar"
+ basedir="build/scratch/qpid-broker-plugins-management-qmf2">
+
+ <service type="org.apache.qpid.server.plugin.PluginFactory"
+ provider="org.apache.qpid.server.qmf2.QmfManagementFactory"/>
+ </jar>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Generates the jar for the the HTTP REST API Server -->
+ <!-- =================================================================== -->
+ <target name="restapi-jar" depends="restapi">
+ <mkdir dir="build/lib"/>
+ <jar destfile="build/lib/restapi.jar" basedir="build/scratch/restapi">
+ </jar>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Generates Javadoc -->
+ <!-- =================================================================== -->
+ <target name="api-doc">
+ <javadoc packagenames="org.apache.qpid.qmf2.*, org.apache.qpid.restapi.*"
+ sourcepath="src/main/java:src/restapi/java"
+ destdir="docs/api"
+ windowtitle="QMF2 API">
+ </javadoc>
+ </target>
+
+ <target name="all-doc">
+ <javadoc packagenames="org.apache.qpid.qmf2.*, org.apache.qpid.restapi.*, org.apache.qpid.server.qmf2.*"
+ sourcepath="src/main/java:src/restapi/java:src/qpid-broker-plugins-management-qmf2/java"
+ destdir="docs/api"
+ windowtitle="QMF2 API">
+ </javadoc>
+ </target>
+
+
+ <!-- =================================================================== -->
+ <!-- Cleans up classes but keeps jars and docs around -->
+ <!-- =================================================================== -->
+ <target name="clean">
+ <delete includeemptydirs="true">
+ <fileset dir="." includes="**/*.class"/>
+ </delete>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Removes everything except the sources enabling clean build. -->
+ <!-- =================================================================== -->
+ <target name="cleanall" depends="clean">
+ <delete includeemptydirs="true">
+ <fileset dir="." includes="**/*.*~ **/*~" defaultexcludes="no"/>
+
+ <fileset dir="${qpid.lib.plugins}" includes="qpid-broker-plugins-management-qmf2.jar qmf2.jar"
+ defaultexcludes="no"/>
+ </delete>
+
+ <delete dir="build"/>
+ <delete dir="docs"/>
+ </target>
+
+</project>
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Agent.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Agent.java
new file mode 100644
index 0000000000..ef94a306c3
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Agent.java
@@ -0,0 +1,1461 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+// JMS Imports
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.AMQPMessage;
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.Notifier;
+import org.apache.qpid.qmf2.common.NotifierWrapper;
+import org.apache.qpid.qmf2.common.NullQmfEventListener;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfCallback;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.SchemaClass;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.common.WorkQueue;
+
+/**
+ * A QMF agent component is represented by a instance of the Agent class. This class is the topmost object
+ * of the Agent application's object model. Associated with a particular agent are:
+ * <pre>
+ * * The set of objects managed by that agent
+ * * The set of schema that describes the structured objects owned by the agent
+ * * A collection of Consoles that are interfacing with the agent
+ * </pre>
+ * The Agent class communicates with the application using the same work-queue model as the Console.
+ * The agent maintains a work-queue of pending requests. Each pending request is associated with a handle.
+ * When the application is done servicing the work request, it passes the response to the agent along with
+ * the handle associated with the originating request.
+ * <p>
+ * The base class for the Agent object is the Agent class. This base class represents a single agent
+ * implementing internal store.
+ *
+ * <h3>Subscriptions</h3>
+ * This implementation of the QMF2 API has full support for QMF2 Subscriptions.
+ * <p>
+ * The diagram below shows the relationship between the Agent, the Subscription and SubscribableAgent interface.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ * <p>
+ * <h3>Receiving Asynchronous Notifications</h3>
+ * This implementation of the QMF2 Agent actually supports two independent APIs to enable clients to receive
+ * Asynchronous notifications.
+ * <p>
+ * A QmfEventListener object is used to receive asynchronously delivered WorkItems.
+ * <p>
+ * This provides an alternative (simpler) API to the official QMF2 WorkQueue API that some (including the Author)
+ * may prefer over the official API.
+ * <p>
+ * The following diagram illustrates the QmfEventListener Event model.
+ * <p>
+ * Notes
+ * <ol>
+ * <li>This is provided as an alternative to the official QMF2 WorkQueue and Notifier Event model.</li>
+ * <li>Agent and Console methods are sufficiently thread safe that it is possible to call them from a callback fired
+ * from the onEvent() method that may have been called from the JMS MessageListener. Internally the synchronous
+ * and asynchronous calls are processed on different JMS Sessions to facilitate this</li>
+ * </ol>
+ * <p>
+ * <img src="doc-files/QmfEventListenerModel.png"/>
+ * <p>
+ * The QMF2 API has a work-queue Callback approach. All asynchronous events are represented by a WorkItem object.
+ * When a QMF event occurs it is translated into a WorkItem object and placed in a FIFO queue. It is left to the
+ * application to drain this queue as needed.
+ * <p>
+ * This new API does require the application to provide a single callback. The callback is used to notify the
+ * application that WorkItem object(s) are pending on the work queue. This callback is invoked by QMF when one or
+ * more new WorkItem objects are added to the queue. To avoid any potential threading issues, the application is
+ * not allowed to call any QMF API from within the context of the callback. The purpose of the callback is to
+ * notify the application to schedule itself to drain the work queue at the next available opportunity.
+ * <p>
+ * For example, a console application may be designed using a select() loop. The application waits in the select()
+ * for any of a number of different descriptors to become ready. In this case, the callback could be written to
+ * simply make one of the descriptors ready, and then return. This would cause the application to exit the wait state,
+ * and start processing pending events.
+ * <p>
+ * The callback is represented by the Notifier virtual base class. This base class contains a single method. An
+ * application derives a custom notification handler from this class, and makes it available to the Console or Agent object.
+ * <p>
+ * The following diagram illustrates the Notifier and WorkQueue QMF2 API Event model.
+ * <p>
+ * Notes
+ * <ol>
+ * <li>There is an alternative (simpler but not officially QMF2) API based on implementing the QmfEventListener as
+ * described previously.</li>
+ * <li>BlockingNotifier is not part of QMF2 either but is how most people would probably write a Notifier.</li>
+ * <li>It's generally not necessary to use a Notifier as the Console provides a blocking getNextWorkitem() method.</li>
+ * </ol>
+ * <p>
+ * <img src="doc-files/WorkQueueEventModel.png"/>
+ * <h3>Potential Issues with Qpid versions earlier than 0.12</h3>
+ * Note 1: This uses QMF2 so requires that the "--mgmt-qmf2 yes" option is applied to the broker (this is the default
+ * from Qpid 0.10).
+ * <p>
+ * Note 2: In order to use QMF2 the app-id field needs to be set. There appears to be no way to set the AMQP 0-10
+ * specific app-id field on a message which the brokers QMFv2 implementation currently requires.
+ * <p>
+ * Gordon Sim has put together a patch for org.apache.qpid.client.message.AMQMessageDelegate_0_10
+ * Found in client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java
+ * <pre>
+ * public void setStringProperty(String propertyName, String value) throws JMSException
+ * {
+ * checkPropertyName(propertyName);
+ * checkWritableProperties();
+ * setApplicationHeader(propertyName, value);
+ *
+ * if ("x-amqp-0-10.app-id".equals(propertyName))
+ * {
+ * _messageProps.setAppId(value.getBytes());
+ * }
+ * }
+ * </pre>
+ * This gets things working.
+ * <p>
+ * A jira <a href=https://issues.apache.org/jira/browse/QPID-3302>QPID-3302</a> has been raised.
+ * This is fixed in Qpid 0.12.
+ *
+ * @author Fraser Adams
+ */
+public class Agent extends QmfData implements MessageListener, SubscribableAgent
+{
+ private static final Logger _log = LoggerFactory.getLogger(Agent.class);
+
+ /**
+ * This TimerTask causes the Agent to sent a Hearbeat when it gets scheduled
+ */
+ private final class Heartbeat extends TimerTask
+ {
+ public void run()
+ {
+ try
+ {
+ String vendorKey = _vendor.replace(".", "_");
+ String productKey = _product.replace(".", "_");
+ String instanceKey = _instance.replace(".", "_");
+ String subject = "agent.ind.heartbeat." + vendorKey + "." + productKey + "." + instanceKey;
+
+ MapMessage response = _syncSession.createMapMessage();
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "indication");
+ response.setStringProperty("qmf.opcode", "_agent_heartbeat_indication");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qpid.subject", subject);
+ setValue("_timestamp", System.currentTimeMillis()*1000000l);
+ response.setObject("_values", mapEncode());
+
+ // Send heartbeat messages with a Time To Live (in msecs) set to two times the _heartbeatInterval
+ // to prevent stale heartbeats from getting to the consoles.
+ _broadcaster.send(response, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
+ _heartbeatInterval*2000);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in sendHeartbeat()", jmse.getMessage());
+ }
+
+ // Reap any QmfAgentData Objects that have been marked as Deleted
+ // Use the iterator approach rather than foreach as we may want to call iterator.remove() to zap an entry
+ Iterator<QmfAgentData> i = _objectIndex.values().iterator();
+ while (i.hasNext())
+ {
+ QmfAgentData object = i.next();
+ if (object.isDeleted())
+ {
+ _log.debug("Removing deleted QmfAgentData Object from store");
+ i.remove();
+ }
+ }
+ }
+ }
+
+ // Attributes
+ // ********************************************************************************************************
+
+ /**
+ * The _eventListener may be a real application QmfEventListener, a NullQmfEventListener or an application
+ * Notifier wrapped in a QmfEventListener. In all cases the Agent may call _eventListener.onEvent() at
+ * various places to pass a WorkItem to an asynchronous receiver.
+ */
+ private QmfEventListener _eventListener;
+
+ /**
+ * _schemaCache holds references to the Schema objects for easy lookup so we can return the info to
+ * the Console if necessary
+ */
+ private Map<SchemaClassId, SchemaClass> _schemaCache = new ConcurrentHashMap<SchemaClassId, SchemaClass>();
+
+ /**
+ * _objectIndex is the global index of QmfAgentData objects registered with this Agent.
+ * The capacity of 100 is pretty arbitrary but the default of 16 seems too low for most Agents.
+ */
+ private Map<ObjectId, QmfAgentData> _objectIndex = new ConcurrentHashMap<ObjectId, QmfAgentData>(100);
+
+ /**
+ * This Map is used to look up Subscriptions by SubscriptionId
+ */
+ private Map<String, Subscription> _subscriptions = new ConcurrentHashMap<String, Subscription>();
+
+ /**
+ * Used to implement a thread safe queue of WorkItem objects used to implement the Notifier API
+ */
+ private WorkQueue _workQueue = new WorkQueue();
+
+ /**
+ * If a name is supplied, it must be unique across all attached to the AMQP bus under the given domain.
+ * The name must comprise three parts separated by colons: <vendor>:<product>[:<instance>], where the
+ * vendor is the Agent vendor name, the product is the Agent product itself and the instance is a UUID
+ * representing the running instance. If the instance is not supplied then a random UUID will be generated
+ */
+ private String _name;
+
+ /**
+ * The Agent vendor name
+ */
+ private String _vendor;
+
+ /**
+ * The Agent product name
+ */
+ private String _product;
+
+ /**
+ * A UUID representing the running instance
+ */
+ private String _instance = UUID.randomUUID().toString();
+
+ /**
+ * The epoch may be used to maintain a count of the number of times an agent has been restarted. By
+ * incrementing this value and keeping a constant instance value an Agent can indicate to a client
+ * that it is a persistent Agent and has been restarted. The Broker Management Agent behaves in this way.
+ */
+ private int _epoch = 1;
+
+ /**
+ * The interval that this Agent waits between sending out hearbeat messages
+ */
+ private int _heartbeatInterval = 30;
+
+ /**
+ * The domain string is used to construct the name of the AMQP exchange to which the component's
+ * name string will be bound. If not supplied, the value of the domain defaults to "default". Both
+ * Agents and Components must belong to the same domain in order to communicate.
+ */
+ private String _domain;
+
+ /**
+ * This timer is used to schedule periodic events such as sending Heartbeats and subscription updates
+ */
+ private Timer _timer;
+
+ /**
+ * Various JMS related fields
+ */
+ private Connection _connection = null;
+ private Session _asyncSession;
+ private Session _syncSession;
+ private MessageConsumer _locateConsumer;
+ private MessageConsumer _mainConsumer;
+ // _aliasConsumer is used for the alias address if the Agent is a broker Agent (used in Java Broker QMF plugin)
+ private MessageConsumer _aliasConsumer;
+ private MessageProducer _responder;
+ private MessageProducer _broadcaster;
+
+ /**
+ * This contains a String representation of the broadcastAddress used to decide whether to use _responder or
+ * _broadcaster as the MessageProducer for Message responses. See the comments for the sendResponse() method below.
+ */
+ private String _broadcastAddress;
+
+ // private implementation methods
+ // ********************************************************************************************************
+
+
+ /**
+ * There's some slight "hackery" below. The Agent clearly needs to respond to requests and quite possibly using
+ * the JMS replyTo is the correct thing to do, however in older versions of Qpid invoking send() on the replyTo
+ * causes spurious exchangeDeclares to occur and the caching of replyTo wasn't as good as it might be.
+ * To get around this the Agent actually uses the relevant exchange name as the core address and sets the Message
+ * "qpid.subject" with an appropriate Routing Key. The problem occurs if Console clients decide to use the
+ * qmf.default.topic as a replyTo instead of qmf.default.direct so we check the start of the replyTo using
+ * _broadcastAddress. It's slightly hacky because the Destination.toString() could change as it's implemenation
+ * specific. That shouldn't be too much of a pain as most clients should use qmf.default.direct.
+ * @param handle the reply handle that contains the replyTo Address.
+ * @param message the JMS Message to be sent.
+ */
+ private final void sendResponse(final Handle handle, final Message message) throws JMSException
+ {
+ // A replyTo looks a bit like 'qmf.default.direct'/'direct.95dab79b-0d3e-4214-9f55-f9efb146c101'; None
+ // so we check if it starts with 'qmf.default.topic' and if so use the _broadcaster MessageProducer
+ // otherwise use the _responder. N.B. if the Destination.toString() format changes this will fail and
+ // always sent to _responder, though *most* clients (hear me qpid-config!!!) use qmf.default.direct.
+ String replyTo = handle.getReplyTo().toString();
+
+ if (replyTo.startsWith(_broadcastAddress))
+ {
+ _broadcaster.send(message);
+ }
+ else
+ {
+ _responder.send(message);
+ }
+ }
+
+ /**
+ * Send an _agent_locate_response back to the Console that requested the locate.
+ * @param handle the reply handle that contains the replyTo Address.
+ */
+ private final void handleLocateRequest(final Handle handle)
+ {
+ try
+ {
+ MapMessage response = _syncSession.createMapMessage();
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "indication");
+ response.setStringProperty("qmf.opcode", "_agent_locate_response");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qpid.subject", handle.getRoutingKey());
+ setValue("_timestamp", System.currentTimeMillis()*1000000l);
+ response.setObject("_values", mapEncode());
+ sendResponse(handle, response);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in handleLocateRequest()", jmse.getMessage());
+ }
+ }
+
+ /**
+ * Handle the query request and send the response back to the Console.
+ * @param handle the reply handle that contains the replyTo Address.
+ * @param query the inbound query from the Console.
+ */
+ @SuppressWarnings("unchecked")
+ private final void handleQueryRequest(final Handle handle, final QmfQuery query)
+ {
+ QmfQueryTarget target = query.getTarget();
+
+ if (target == QmfQueryTarget.SCHEMA_ID)
+ {
+ List<Map> results = new ArrayList<Map>(_schemaCache.size());
+ // Look up all SchemaClassId objects
+ for (SchemaClassId classId : _schemaCache.keySet())
+ {
+ results.add(classId.mapEncode());
+ }
+ queryResponse(handle, results, "_schema_id"); // Send the response back to the Console.
+ }
+ else if (target == QmfQueryTarget.SCHEMA)
+ {
+ List<Map> results = new ArrayList<Map>(1);
+ // Look up a SchemaClass object by the SchemaClassId obtained from the query
+ SchemaClassId classId = query.getSchemaClassId();
+ SchemaClass schema = _schemaCache.get(classId);
+ if (schema != null)
+ {
+ results.add(schema.mapEncode());
+ }
+ queryResponse(handle, results, "_schema"); // Send the response back to the Console.
+ }
+ else if (target == QmfQueryTarget.OBJECT_ID)
+ {
+ List<Map> results = new ArrayList<Map>(_objectIndex.size());
+ // Look up all ObjectId objects
+ for (ObjectId objectId : _objectIndex.keySet())
+ {
+ results.add(objectId.mapEncode());
+ }
+ queryResponse(handle, results, "_object_id"); // Send the response back to the Console.
+ }
+ else if (target == QmfQueryTarget.OBJECT)
+ {
+ // If this is implementing the AgentExternal model we pass the QmfQuery on in a QueryWorkItem
+ if (this instanceof AgentExternal)
+ {
+ _eventListener.onEvent(new QueryWorkItem(handle, query));
+ return;
+ }
+ else
+ { // If not implementing the AgentExternal model we handle the Query ourself.
+ //qmfContentType = "_data";
+ if (query.getObjectId() != null)
+ {
+ List<Map> results = new ArrayList<Map>(1);
+ // Look up a QmfAgentData object by the ObjectId obtained from the query
+ ObjectId objectId = query.getObjectId();
+ QmfAgentData object = _objectIndex.get(objectId);
+ if (object != null && !object.isDeleted())
+ {
+ results.add(object.mapEncode());
+ }
+ queryResponse(handle, results, "_data"); // Send the response back to the Console.
+ }
+ else
+ {
+ // Look up QmfAgentData objects by the SchemaClassId obtained from the query
+ // This is implemented by a linear search and allows searches with only the className specified.
+ // Linear searches clearly don't scale brilliantly, but the number of QmfAgentData objects managed
+ // by an Agent is generally fairly small, so it should be OK. Note that this is the same approach
+ // taken by the C++ broker ManagementAgent, so if it's a problem here........
+
+ // N.B. the results list declared here is a generic List of Objects. We *must* only pass a List of
+ // Map to queryResponse(), but conversely if the response items are sortable we need tp sort them
+ // before doing mapEncode(). Unfortunately we don't know if the items are sortable a priori so
+ // we either add a Map or we add a QmfAgentData, then sort then mapEncode() each item. I'm not
+ // sure of a more elegant way to do this without creating two lists, which might not be so bad
+ // but we don't know the size of the list a priori either.
+ List results = new ArrayList(_objectIndex.size());
+ // It's unlikely that evaluating this query will return a mixture of sortable and notSortable
+ // QmfAgentData objects, but it's best to check if that has occurred as accidentally passing a
+ // List of QmfAgentData instead of a List of Map to queryResponse() will break things.
+ boolean sortable = false;
+ boolean notSortable = false;
+ for (QmfAgentData object : _objectIndex.values())
+ {
+ if (!object.isDeleted() && query.evaluate(object))
+ {
+ if (object.isSortable())
+ { // If QmfAgentData is marked sortable we add the QmfAgentData object to the List
+ // so we can sort first before mapEncoding.
+ results.add(object);
+ sortable = true;
+ }
+ else
+ { // If QmfAgentData is not marked sortable we mapEncode immediately and add the Map to List.
+ results.add(object.mapEncode());
+ notSortable = true;
+ }
+ }
+ }
+
+ // If both flags have been set something has gone a bit weird, so we log an error and clear the
+ // results List to avoid sending unconvertable data. Hopefully this condition should never occur.
+ if (sortable && notSortable)
+ {
+ _log.info("Query resulted in inconsistent mixture of sortable and non-sortable data.");
+ results.clear();
+ }
+ else if (sortable)
+ {
+ Collections.sort(results);
+ int length = results.size();
+ for (int i = 0; i < length; i++)
+ {
+ QmfAgentData object = (QmfAgentData)results.get(i);
+ results.set(i, object.mapEncode());
+ }
+ }
+ queryResponse(handle, results, "_data"); // Send the response back to the Console.
+ }
+ }
+ }
+ else
+ {
+ raiseException(handle, "Query for _what => '" + target + "' not supported");
+ return;
+ }
+ } // end of handleQueryRequest()
+
+ /**
+ * Return a QmfAgentData from the internal Object store given its ObjectId.
+ * N.B. This method isn't part of the *official* QMF2 public API, however it is pretty useful and probably
+ * should be (as should evaluateQuery()). Given that wi.getType() == METHOD_CALL primarily uses the pattern:
+ * <pre>
+ * MethodCallWorkItem item = (MethodCallWorkItem)wi;
+ * MethodCallParams methodCallParams = item.getMethodCallParams();
+ * String methodName = methodCallParams.getName();
+ * ObjectId objectId = methodCallParams.getObjectId();
+ * </pre>
+ * to identify the method name and Object instance it seems odd not to have a public API method to look up
+ * said Object by ObjectId. Clearly a separate Map could be maintained in client code but that seems pointless.
+ */
+ public final QmfAgentData getObject(ObjectId objectId)
+ {
+ return _objectIndex.get(objectId);
+ }
+
+ /**
+ * Send an exception back to the Console.
+ * @param handle the reply handle that contains the replyTo Address.
+ * @param message the exception message.
+ */
+ public final void raiseException(final Handle handle, final String message)
+ {
+ try
+ {
+ MapMessage response = _syncSession.createMapMessage();
+ response.setJMSCorrelationID(handle.getCorrelationId());
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "response");
+ response.setStringProperty("qmf.opcode", "_exception");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qpid.subject", handle.getRoutingKey());
+
+ QmfData exception = new QmfData();
+ exception.setValue("error_text", message);
+ response.setObject("_values", exception.mapEncode());
+ sendResponse(handle, response);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in handleLocateRequest()", jmse.getMessage());
+ }
+ }
+
+ // methods implementing SubscribableAgent interface
+ // ********************************************************************************************************
+
+ /**
+ * Send a list of updated subscribed data to the Console.
+ *
+ * @param handle the console reply handle.
+ * @param results a list of subscribed data in Map encoded form.
+ */
+ public final void sendSubscriptionIndicate(final Handle handle, final List<Map> results)
+ {
+ try
+ {
+ Message response = AMQPMessage.createListMessage(_syncSession);
+ response.setJMSCorrelationID(handle.getCorrelationId());
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "indication");
+ response.setStringProperty("qmf.opcode", "_data_indication");
+ response.setStringProperty("qmf.content", "_data");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qpid.subject", handle.getRoutingKey());
+ AMQPMessage.setList(response, results);
+ sendResponse(handle, response);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in sendSubscriptionIndicate()", jmse.getMessage());
+ }
+ }
+
+ /**
+ * This method evaluates a QmfQuery over the Agent's data on behalf of a Subscription.
+ *
+ * @param query the QmfQuery that the Subscription wants to be evaluated over the Agent's data.
+ * @return a List of QmfAgentData objects that match the specified QmfQuery.
+ */
+ public final List<QmfAgentData> evaluateQuery(final QmfQuery query)
+ {
+ List<QmfAgentData> results = new ArrayList<QmfAgentData>(_objectIndex.size());
+ if (query.getTarget() == QmfQueryTarget.OBJECT)
+ { // Note that we don't include objects marked as deleted in the results here, because if an object gets
+ // destroyed we asynchronously publish its new state to subscribers, see QmfAgentData.destroy() method.
+ if (query.getObjectId() != null)
+ {
+ // Look up a QmfAgentData object by the ObjectId obtained from the query
+ ObjectId objectId = query.getObjectId();
+ QmfAgentData object = _objectIndex.get(objectId);
+ if (object != null && !object.isDeleted())
+ {
+ results.add(object);
+ }
+ }
+ else
+ {
+ // Look up QmfAgentData objects evaluating the query
+ for (QmfAgentData object : _objectIndex.values())
+ {
+ if (!object.isDeleted() && query.evaluate(object))
+ {
+ results.add(object);
+ }
+ }
+ }
+ }
+ return results;
+ }
+
+ /**
+ * This method is called by the Subscription to tell the SubscribableAgent that the Subscription has been cancelled.
+ *
+ * @param subscription the Subscription that has been cancelled and is requesting removal.
+ */
+ public final void removeSubscription(final Subscription subscription)
+ {
+ _subscriptions.remove(subscription.getSubscriptionId());
+ }
+
+ // MessageListener
+ // ********************************************************************************************************
+
+ /**
+ * MessageListener for QMF2 Console requests.
+ *
+ * @param message the JMS Message passed to the listener.
+ */
+ public final void onMessage(final Message message)
+ {
+ try
+ {
+ String agentName = QmfData.getString(message.getObjectProperty("qmf.agent"));
+ String content = QmfData.getString(message.getObjectProperty("qmf.content"));
+ String opcode = QmfData.getString(message.getObjectProperty("qmf.opcode"));
+ //String routingKey = ((javax.jms.Topic)message.getJMSDestination()).getTopicName();
+ //String contentType = ((org.apache.qpid.client.message.AbstractJMSMessage)message).getContentType();
+
+//System.out.println();
+//System.out.println("agentName = " + agentName);
+//System.out.println("content = " + content);
+//System.out.println("opcode = " + opcode);
+//System.out.println("routingKey = " + routingKey);
+//System.out.println("contentType = " + contentType);
+
+ Handle handle = new Handle(message.getJMSCorrelationID(), message.getJMSReplyTo());
+
+ if (opcode.equals("_agent_locate_request"))
+ {
+ handleLocateRequest(handle);
+ }
+ else if (opcode.equals("_method_request"))
+ {
+ if (AMQPMessage.isAMQPMap(message))
+ {
+ _eventListener.onEvent
+ (
+ new MethodCallWorkItem(handle, new MethodCallParams(AMQPMessage.getMap(message)))
+ );
+ }
+ else
+ {
+ _log.info("onMessage() Received Method Request message in incorrect format");
+ }
+ }
+ else if (opcode.equals("_query_request"))
+ {
+ if (AMQPMessage.isAMQPMap(message))
+ {
+ try
+ {
+ QmfQuery query = new QmfQuery(AMQPMessage.getMap(message));
+ handleQueryRequest(handle, query);
+ }
+ catch (QmfException qmfe)
+ {
+ raiseException(handle, "Query Request failed, invalid Query: " + qmfe.getMessage());
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Query Request message in incorrect format");
+ }
+ }
+ else if (opcode.equals("_subscribe_request"))
+ {
+ if (AMQPMessage.isAMQPMap(message))
+ {
+ try
+ {
+ SubscriptionParams subscriptionParams =
+ new SubscriptionParams(handle, AMQPMessage.getMap(message));
+ if (this instanceof AgentExternal)
+ {
+ _eventListener.onEvent(new SubscribeRequestWorkItem(handle, subscriptionParams));
+ }
+ else
+ {
+ Subscription subscription = new Subscription(this, subscriptionParams);
+ String subscriptionId = subscription.getSubscriptionId();
+ _subscriptions.put(subscriptionId, subscription);
+ _timer.schedule(subscription, 0, subscriptionParams.getPublishInterval());
+ subscriptionResponse(handle, subscription.getConsoleHandle(), subscriptionId,
+ subscription.getDuration(), subscription.getInterval(), null);
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ raiseException(handle, "Subscribe Request failed, invalid Query: " + qmfe.getMessage());
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Subscribe Request message in incorrect format");
+ }
+ }
+ else if (opcode.equals("_subscribe_refresh_indication"))
+ {
+ if (AMQPMessage.isAMQPMap(message))
+ {
+ ResubscribeParams resubscribeParams = new ResubscribeParams(AMQPMessage.getMap(message));
+ if (this instanceof AgentExternal)
+ {
+ _eventListener.onEvent(new ResubscribeRequestWorkItem(handle, resubscribeParams));
+ }
+ else
+ {
+ String subscriptionId = resubscribeParams.getSubscriptionId();
+ Subscription subscription = _subscriptions.get(subscriptionId);
+ if (subscription != null)
+ {
+ subscription.refresh(resubscribeParams);
+ subscriptionResponse(handle,
+ subscription.getConsoleHandle(), subscription.getSubscriptionId(),
+ subscription.getDuration(), subscription.getInterval(), null);
+ }
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Resubscribe Request message in incorrect format");
+ }
+ }
+ else if (opcode.equals("_subscribe_cancel_indication"))
+ {
+ if (AMQPMessage.isAMQPMap(message))
+ {
+ QmfData qmfSubscribe = new QmfData(AMQPMessage.getMap(message));
+ String subscriptionId = qmfSubscribe.getStringValue("_subscription_id");
+ if (this instanceof AgentExternal)
+ {
+ _eventListener.onEvent(new UnsubscribeRequestWorkItem(subscriptionId));
+ }
+ else
+ {
+ Subscription subscription = _subscriptions.get(subscriptionId);
+ if (subscription != null)
+ {
+ subscription.cancel();
+ }
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Subscribe Cancel Request message in incorrect format");
+ }
+ }
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in onMessage()", jmse.getMessage());
+ }
+ } // end of onMessage()
+
+ // QMF API Methods
+ // ********************************************************************************************************
+
+ /**
+ * Constructor that provides defaults for name, domain and heartbeat interval and takes a Notifier/Listener.
+ *
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread.
+ * <p>
+ * This API may be simpler and more convenient than the QMF2 Notifier API for many applications.
+ */
+ public Agent(final QmfCallback notifier) throws QmfException
+ {
+ this(null, null, notifier, 30);
+ }
+
+ /**
+ * Constructor that provides defaults for name and domain and takes a Notifier/Listener
+ *
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread.
+ * <p>
+ * This API may be simpler and more convenient than the QMF2 Notifier API for many applications.
+ * @param interval is the heartbeat interval in seconds.
+ */
+ public Agent(final QmfCallback notifier, final int interval) throws QmfException
+ {
+ this(null, null, notifier, interval);
+ }
+
+ /**
+ * Main constructor, creates a Agent, but does NOT start it, that requires us to do setConnection()
+ *
+ * @param name If a name is supplied, it must be unique across all agents attached to the AMQP bus under the
+ * given domain.
+ * <p>
+ * The name must comprise three parts separated by colons: <pre>&lt;vendor&gt;:&lt;product&gt;[:&lt;instance&gt;]</pre>
+ * where the vendor is the Agent vendor name, the product is the Agent product itself and the instance is a UUID
+ * representing the running instance.
+ * <p>
+ * If the instance is not supplied then a random UUID will be generated.
+ * @param domain the QMF "domain".
+ * <p>
+ * A QMF address is composed of two parts - an optional domain string, and a mandatory name string
+ * <pre>"qmf.&lt;domain-string&gt;.direct/&lt;name-string&gt;"</pre>
+ * The domain string is used to construct the name of the AMQP exchange to which the component's name string will
+ * be bound. If not supplied, the value of the domain defaults to "default".
+ * <p>
+ * Both Agents and Consoles must belong to the same domain in order to communicate.
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread.
+ * <p>
+ * This API may be simpler and more convenient than the QMF2 Notifier API for many applications.
+ * @param interval is the heartbeat interval in seconds.
+ */
+ public Agent(final String name, final String domain,
+ final QmfCallback notifier, final int interval) throws QmfException
+ {
+ if (name != null)
+ {
+ String[] split = name.split(":");
+ if (split.length < 2 || split.length > 3)
+ {
+ throw new QmfException("Agent name must be in the format <vendor>:<product>[:<instance>]");
+ }
+
+ _vendor = split[0];
+ _product = split[1];
+
+ if (split.length == 3)
+ {
+ _instance = split[2];
+ }
+
+ _name = _vendor + ":" + _product + ":" + _instance;
+ }
+
+ _domain = (domain == null) ? "default" : domain;
+
+ if (notifier == null)
+ {
+ _eventListener = new NullQmfEventListener();
+ }
+ else if (notifier instanceof Notifier)
+ {
+ _eventListener = new NotifierWrapper((Notifier)notifier, _workQueue);
+ }
+ else if (notifier instanceof QmfEventListener)
+ {
+ _eventListener = (QmfEventListener)notifier;
+ }
+ else
+ {
+ throw new QmfException("QmfCallback listener must be either a Notifier or QmfEventListener");
+ }
+
+ if (interval > 0)
+ {
+ _heartbeatInterval = interval;
+ }
+ }
+
+ /**
+ * Returns the name string of the agent.
+ * @return the name string of the agent.
+ */
+ public final String getName()
+ {
+ return _name;
+ }
+
+ /**
+ * Set the vendor String, must be called before setConnection().
+ * @param vendor the vendor name.
+ */
+ public final void setVendor(final String vendor)
+ {
+ _vendor = vendor;
+ _name = _vendor + ":" + _product + ":" + _instance;
+ }
+
+ /**
+ * Set the product String, must be called before setConnection().
+ * @param product the product name.
+ */
+ public final void setProduct(final String product)
+ {
+ _product = product;
+ _name = _vendor + ":" + _product + ":" + _instance;
+ }
+
+ /**
+ * Set the instance String, must be called before setConnection().
+ * @param instance the instance value.
+ */
+ public final void setInstance(final String instance)
+ {
+ _instance = instance;
+ _name = _vendor + ":" + _product + ":" + _instance;
+ }
+
+ /**
+ * Returns the current epoch value.
+ * @return the current epoch value.
+ */
+ public final int getEpoch()
+ {
+ return _epoch;
+ }
+
+ /**
+ * Set the new epoch value.
+ * @param epoch the new epoch value.
+ */
+ public final void setEpoch(final int epoch)
+ {
+ _epoch = epoch;
+ }
+
+ /**
+ * Releases Agent's resources.
+ */
+ public final void destroy()
+ {
+ try
+ {
+ if (_connection != null)
+ {
+ removeConnection(_connection);
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ // Ignore as we've already tested for _connection != null this should never occur
+ }
+ }
+
+ /**
+ * Connect the Agent to the AMQP cloud.
+ *
+ * @param conn a javax.jms.Connection.
+ */
+ public final void setConnection(final Connection conn) throws QmfException
+ {
+ setConnection(conn, "");
+ }
+
+ /**
+ * Connect the Agent to the AMQP cloud.
+ * <p>
+ * This is an extension to the standard QMF2 API allowing the user to specify address options in order to allow
+ * finer control over the Agent's ingest queue, such as an explicit name, non-default size or durability.
+ *
+ * @param conn a javax.jms.Connection.
+ * @param addressOptions options String giving finer grained control of the receiver queue.
+ * <p>
+ * As an example the following gives the Agent's ingest queue the name test-agent, size = 500000000 and ring policy.
+ * <pre>
+ * " ; {link: {name:'test-agent', x-declare: {arguments: {'qpid.policy_type': ring, 'qpid.max_size': 500000000}}}}"
+ * </pre>
+ */
+ public final void setConnection(final Connection conn, final String addressOptions) throws QmfException
+ {
+ // Make the test and set of _connection synchronized just in case multiple threads attempt to add a _connection
+ // to the same Agent instance at the same time.
+ synchronized(this)
+ {
+ if (_connection != null)
+ {
+ throw new QmfException("Multiple connections per Agent is not supported");
+ }
+ _connection = conn;
+ }
+
+ if (_name == null || _vendor == null || _product == null)
+ {
+ throw new QmfException("The vendor, product or name is not set");
+ }
+
+ setValue("_epoch", _epoch);
+ setValue("_heartbeat_interval", _heartbeatInterval);
+ setValue("_name", _name);
+ setValue("_product", _product);
+ setValue("_vendor", _vendor);
+ setValue("_instance", _instance);
+
+ try
+ {
+ String directBase = "qmf." + _domain + ".direct";
+ String topicBase = "qmf." + _domain + ".topic";
+ String address = directBase + "/" + _name + addressOptions;
+
+ _asyncSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ _syncSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Create a MessageProducer for the QMF topic address used to broadcast Events & Heartbeats.
+ Destination topicAddress = _syncSession.createQueue(topicBase);
+ _broadcaster = _syncSession.createProducer(topicAddress);
+ _broadcastAddress = "'" + topicBase + "'";
+
+ // Create a MessageProducer for the QMF direct address, mainly used for request/response
+ Destination directAddress = _syncSession.createQueue(directBase);
+ _responder = _syncSession.createProducer(directAddress);
+
+ // TODO it should be possible to bind _locateConsumer, _mainConsumer and _aliasConsumer to the
+ // same queue if I can figure out the correct AddressString to use, probably not a big deal though.
+
+ // Set up MessageListener on the Agent Locate Address
+ Destination locateAddress = _asyncSession.createQueue(topicBase + "/console.request.agent_locate");
+ _locateConsumer = _asyncSession.createConsumer(locateAddress);
+ _locateConsumer.setMessageListener(this);
+
+ // Set up MessageListener on the Agent address
+ Destination agentAddress = _asyncSession.createQueue(address);
+ _mainConsumer = _asyncSession.createConsumer(agentAddress);
+ _mainConsumer.setMessageListener(this);
+
+ // If the product name has been set to qpidd we create an additional consumer address of
+ // "qmf.default.direct/broker" in addition to the main address so that Consoles can talk to the
+ // broker Agent without needing to do Agent discovery. This is only really needed when the Agent
+ // class has been used to create the QmfManagementAgent for the Java broker QmfManagementPlugin.
+ // It's important to do this as many tools (such as qpid-config) and demo code tend to use the
+ // alias address rather than the discovered address when talking to the broker ManagementAgent.
+ if (_product.equals("qpidd"))
+ {
+ String alias = directBase + "/broker";
+ _log.info("Creating address {} as an alias address for the broker Agent", alias);
+ Destination aliasAddress = _asyncSession.createQueue(alias);
+ _aliasConsumer = _asyncSession.createConsumer(aliasAddress);
+ _aliasConsumer.setMessageListener(this);
+ }
+
+ _connection.start();
+
+ // Schedule a Heartbeat every _heartbeatInterval seconds sending the first one immediately
+ _timer = new Timer(true);
+ _timer.schedule(new Heartbeat(), 0, _heartbeatInterval*1000);
+ }
+ catch (JMSException jmse)
+ {
+ // If we can't create the QMF Destinations there's not much else we can do
+ _log.info("JMSException {} caught in setConnection()", jmse.getMessage());
+ throw new QmfException("Failed to create sessions or destinations " + jmse.getMessage());
+ }
+ } // end of setConnection()
+
+ /**
+ * Remove the AMQP connection from the Agent. Un-does the setConnection() operation.
+ *
+ * @param conn a javax.jms.Connection.
+ */
+ public final void removeConnection(final Connection conn) throws QmfException
+ {
+ if (conn != _connection)
+ {
+ throw new QmfException("Attempt to delete unknown connection");
+ }
+
+ try
+ {
+ _timer.cancel();
+ _connection.close();
+ }
+ catch (JMSException jmse)
+ {
+ throw new QmfException("Failed to remove connection, caught JMSException " + jmse.getMessage());
+ }
+ _connection = null;
+ }
+
+ /**
+ * Register a schema for an object class with the Agent.
+ * <p>
+ * The Agent must have a registered schema for an object class before it can handle objects of that class.
+ *
+ * @param schema the SchemaObjectClass to be registered
+ */
+ public final void registerObjectClass(final SchemaObjectClass schema)
+ {
+ SchemaClassId classId = schema.getClassId();
+ _schemaCache.put(classId, schema);
+ }
+
+ /**
+ * Register a schema for an event class with the Agent.
+ * <p>
+ * The Agent must have a registered schema for an event class before it can handle events of that class.
+ *
+ * @param schema the SchemaEventClass to be registered
+ */
+ public final void registerEventClass(final SchemaEventClass schema)
+ {
+ SchemaClassId classId = schema.getClassId();
+ _schemaCache.put(classId, schema);
+ }
+
+ /**
+ * Cause the agent to raise the given event.
+ *
+ * @param event the QmfEvent to be raised
+ */
+ public final void raiseEvent(final QmfEvent event)
+ {
+ try
+ {
+ String packageKey = event.getSchemaClassId().getPackageName().replace(".", "_");
+ String nameKey = event.getSchemaClassId().getClassName().replace(".", "_");
+ String severity = event.getSeverity();
+ String vendorKey = _vendor.replace(".", "_");
+ String productKey = _product.replace(".", "_");
+ String instanceKey = _instance.replace(".", "_");
+
+ String subject = "agent.ind.event." + packageKey + "." + nameKey + "." + severity + "." + vendorKey + "." +
+ productKey + "." + instanceKey;
+
+ Message response = AMQPMessage.createListMessage(_syncSession);
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "indication");
+ response.setStringProperty("qmf.opcode", "_data_indication");
+ response.setStringProperty("qmf.content", "_event");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qpid.subject", subject);
+ List<Map> results = new ArrayList<Map>();
+ results.add(event.mapEncode());
+ AMQPMessage.setList(response, results);
+ _broadcaster.send(response);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in raiseEvent()", jmse.getMessage());
+ }
+ }
+
+ /**
+ * Passes a reference to an instance of a managed QMF object to the Agent.
+ * <p>
+ * The object's name must uniquely identify this object among all objects known to this Agent.
+ * <p>
+ * This method creates an ObjectId for the QmfAgentData being added, it does this by first checking
+ * the schema.
+ * <p>
+ * If an associated schema exists we look for the set of property names that have been
+ * specified as idNames. If idNames exists we look for their values within the object and use that
+ * to create the objectName. If we can't create a sensible name we use a randomUUID.
+ * @param object the QmfAgentData object to be added
+ */
+ public void addObject(final QmfAgentData object) throws QmfException
+ {
+ // There are some cases where a QmfAgentData Object might have already set its ObjectId, for example where
+ // it may need to have a "well known" ObjectId. This is the case with the Java Broker Management Agent
+ // where tools such as qpid-config might have made assumptions about its ObjectId rather than doing "discovery".
+ ObjectId addr = object.getObjectId();
+ if (addr == null)
+ {
+ SchemaClassId classId = object.getSchemaClassId();
+ SchemaClass schema = _schemaCache.get(classId);
+
+ // Try to create an objectName using the property names that have been specified as idNames in the schema
+ StringBuilder buf = new StringBuilder();
+ // Initialise idNames as an empty array as we want to check if a key has been used to construct the name.
+ String[] idNames = {};
+ if (schema != null && schema instanceof SchemaObjectClass)
+ {
+ idNames = ((SchemaObjectClass)schema).getIdNames();
+ for (String property : idNames)
+ {
+ buf.append(object.getStringValue(property));
+ }
+ }
+ String objectName = buf.toString();
+
+ // If the schema hasn't given any help we use a UUID. Note that we check the length of idNames too
+ // as a given named key property might legitimately be an empty string (e.g. the default direct
+ // exchange has name == "")
+ if (objectName.length() == 0 && idNames.length == 0) objectName = UUID.randomUUID().toString();
+
+ // Finish up the name by incorporating package and class names
+ objectName = classId.getPackageName() + ":" + classId.getClassName() + ":" + objectName;
+
+ // Now we've got a good name for the object we create its ObjectId and add that to the object
+ addr = new ObjectId(_name, objectName, _epoch);
+
+ object.setObjectId(addr);
+ }
+
+ QmfAgentData foundObject = _objectIndex.get(addr);
+ if (foundObject != null)
+ {
+ // If a duplicate object has actually been Deleted we can reuse the address.
+ if (!foundObject.isDeleted())
+ {
+ throw new QmfException("Duplicate QmfAgentData Address");
+ }
+ }
+
+ _objectIndex.put(addr, object);
+
+ // Does the new object match any Subscriptions? If so add a reference to the matching Subscription and publish.
+ for (Subscription subscription : _subscriptions.values())
+ {
+ QmfQuery query = subscription.getQuery();
+ if (query.getObjectId() != null)
+ {
+ if (query.getObjectId().equals(addr))
+ {
+ object.addSubscription(subscription.getSubscriptionId(), subscription);
+ object.publish();
+ }
+ }
+ else if (query.evaluate(object))
+ {
+ object.addSubscription(subscription.getSubscriptionId(), subscription);
+ object.publish();
+ }
+ }
+ } // end of addObject()
+
+ /**
+ * Returns the count of pending WorkItems that can be retrieved.
+ * @return the count of pending WorkItems that can be retrieved.
+ */
+ public final int getWorkitemCount()
+ {
+ return _workQueue.size();
+ }
+
+ /**
+ * Obtains the next pending work item - blocking version.
+ * <p>
+ * The blocking getNextWorkitem() can be used without the need for a Notifier as it will block until
+ * a new item gets added to the work queue e.g. the following usage pattern.
+ * <pre>
+ * while ((wi = agent.getNextWorkitem()) != null)
+ * {
+ * System.out.println("WorkItem type: " + wi.getType());
+ * }
+ * </pre>
+ * @return the next pending work item, or null if none available.
+ */
+ public final WorkItem getNextWorkitem()
+ {
+ return _workQueue.getNextWorkitem();
+ }
+
+ /**
+ * Obtains the next pending work item - balking version.
+ * <p>
+ * The balking getNextWorkitem() is generally used with a Notifier which can be used as a gate to determine
+ * if any work items are available e.g. the following usage pattern.
+ * <pre>
+ * while (true)
+ * {
+ * notifier.waitForWorkItem(); // Assuming a BlockingNotifier has been used here
+ * System.out.println("WorkItem available, count = " + agent.getWorkitemCount());
+ *
+ * WorkItem wi;
+ * while ((wi = agent.getNextWorkitem(0)) != null)
+ * {
+ * System.out.println("WorkItem type: " + wi.getType());
+ * }
+ * }
+ * </pre>
+ * Note that it is possible for the getNextWorkitem() loop to retrieve multiple items from the _workQueue
+ * and for the Agent to add new items as the loop is looping thus when it finally exits and goes
+ * back to the outer loop notifier.waitForWorkItems() may return immediately as it had been notified
+ * whilst we were in the getNextWorkitem() loop. This will be evident by a getWorkitemCount() of 0
+ * after returning from waitForWorkItem().
+ * <p>
+ * This is the expected behaviour, but illustrates the need to check for nullness of the value returned
+ * by getNextWorkitem() - or alternatively to use getWorkitemCount() to put getNextWorkitem() in a
+ * bounded loop.
+ *
+ * @param timeout the timeout in seconds. If timeout = 0 it returns immediately with either a WorkItem or null
+ * @return the next pending work item, or null if none available.
+ */
+ public final WorkItem getNextWorkitem(final long timeout)
+ {
+ return _workQueue.getNextWorkitem(timeout);
+ }
+
+ /**
+ * Releases a WorkItem instance obtained by getNextWorkItem(). Called when the application has finished
+ * processing the WorkItem.
+ */
+ public final void releaseWorkitem()
+ {
+ // To be honest I'm not clear what the intent of this method actually is. One thought is that it's here
+ // to support equivalent behaviour to the Python Queue.task_done() which is used by queue consumer threads.
+ // For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing
+ // on the task is complete.
+ //
+ // The problem with that theory is there is no equivalent QMF2 API call that would invoke the
+ // Queue.join() which is used in conjunction with Queue.task_done() to enable a synchronisation gate to
+ // be implemented to wait for completion of all worker thread.
+ //
+ // I'm a bit stumped and there's no obvious Java equivalent on BlockingQueue, so for now this does nothing.
+ }
+
+ /**
+ * Indicate to the Agent that the application has completed processing a method request.
+ * <p>
+ * See the description of the METHOD_CALL WorkItem.
+ * @param methodName the method's name.
+ * @param handle the reply handle from WorkItem.
+ * @param outArgs the output argument map.
+ * @param error the error object that was created if the method failed in any way, otherwise null.
+ */
+ public final void methodResponse(final String methodName, final Handle handle,
+ final QmfData outArgs, final QmfData error)
+ {
+ try
+ {
+ MapMessage response = _syncSession.createMapMessage();
+ response.setJMSCorrelationID(handle.getCorrelationId());
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "response");
+ response.setStringProperty("qmf.opcode", "_method_response");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qpid.subject", handle.getRoutingKey());
+
+ if (error == null)
+ {
+ if (outArgs != null)
+ {
+ response.setObject("_arguments", outArgs.mapEncode());
+ if (outArgs.getSubtypes() != null)
+ {
+ response.setObject("_subtypes", outArgs.getSubtypes());
+ }
+ }
+ }
+ else
+ {
+ Map<String, Object> errorMap = error.mapEncode();
+ for (Map.Entry<String, Object> entry : errorMap.entrySet())
+ {
+ response.setObject(entry.getKey(), entry.getValue());
+ }
+ }
+ sendResponse(handle, response);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in methodResponse()", jmse.getMessage());
+ }
+ }
+
+ /**
+ * Send the query response back to the Console.
+ * @param handle the reply handle that contains the replyTo Address.
+ * @param results the list of mapEncoded query results.
+ * @param qmfContentType the value to be passed to the qmf.content Header.
+ */
+ protected final void queryResponse(final Handle handle, List<Map> results, final String qmfContentType)
+ {
+ try
+ {
+ Message response = AMQPMessage.createListMessage(_syncSession);
+ response.setJMSCorrelationID(handle.getCorrelationId());
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "response");
+ response.setStringProperty("qmf.opcode", "_query_response");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qmf.content", qmfContentType);
+ response.setStringProperty("qpid.subject", handle.getRoutingKey());
+ AMQPMessage.setList(response, results);
+ sendResponse(handle, response);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in queryResponse()", jmse.getMessage());
+ }
+ }
+
+ /**
+ * If the subscription request is successful, the Agent application must provide a unique subscriptionId.
+ * <p>
+ * If replying to a sucessful subscription refresh, the original subscriptionId must be supplied.
+ * <p>
+ * If the subscription or refresh fails, the subscriptionId should be set to null and error may be set to
+ * an application-specific QmfData instance that describes the error.
+ * <p>
+ * Should a refresh request fail, the consoleHandle may be set to null if unknown.
+ *
+ * @param handle the handle from the WorkItem.
+ * @param consoleHandle the console reply handle.
+ * @param subscriptionId a unique handle for the subscription supplied by the Agent.
+ * @param lifetime should be set to the duration of the subscription in seconds.
+ * @param publishInterval should be set to the time interval in seconds between successive publications
+ * on this subscription.
+ * @param error an application-specific QmfData instance that describes the error.
+ */
+ public final void subscriptionResponse(final Handle handle, final Handle consoleHandle, final String subscriptionId,
+ final long lifetime, final long publishInterval, final QmfData error)
+ {
+ try
+ {
+ MapMessage response = _syncSession.createMapMessage();
+ response.setJMSCorrelationID(handle.getCorrelationId());
+ response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ response.setStringProperty("method", "response");
+ response.setStringProperty("qmf.opcode", "_subscribe_response");
+ response.setStringProperty("qmf.agent", _name);
+ response.setStringProperty("qpid.subject", handle.getRoutingKey());
+
+ if (error == null)
+ {
+ response.setObject("_subscription_id", subscriptionId);
+ response.setObject("_duration", lifetime);
+ response.setObject("_interval", publishInterval);
+ }
+ else
+ {
+ Map<String, Object> errorMap = error.mapEncode();
+ for (Map.Entry<String, Object> entry : errorMap.entrySet())
+ {
+ response.setObject(entry.getKey(), entry.getValue());
+ }
+ }
+ sendResponse(handle, response);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in subscriptionResponse()", jmse.getMessage());
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/AgentExternal.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/AgentExternal.java
new file mode 100644
index 0000000000..2fff3fd41f
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/AgentExternal.java
@@ -0,0 +1,259 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfCallback;
+import org.apache.qpid.qmf2.common.QmfException;
+
+/**
+ * The AgentExternal class must be used by those applications that implement the external store model described in
+ * <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>.
+ * <p>
+ * The AgentExternal class extends the Agent class by adding interfaces that notify the application when it needs to
+ * service a request for management operations from the agent.
+ * <p>
+ * N.B. The author is not convinced that there is any particular advantage of the AgentExternal model over the
+ * basic Agent model and indeed the API forces some constructs that are actually likely to be less efficient, as an
+ * example sending a separate queryResponse() for each object forces a look up of a List of QmfAgentData objects
+ * keyed by the consoleHandle for each call. There is also the need to separately iterate through the List of
+ * QmfAgentData objects thus created to create the mapEncoded list needed for sending via the QMF2 protocol.
+ * There are similar inefficiencies imposed in the subscriptionIndicate() method that are not present in the
+ * Subscription code implemented in the Agent class for the "Internal Store" Agent model.
+ * <p>
+ * To be honest the author only bothered to implement AgentExternal for completeness and is unlikely to use it himself.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentExternal extends Agent
+{
+ /**
+ * This Map is used to hold query results. This is necessary as the API has each queryResponse() call send
+ * back an individual QmfAgentData, so we need to maintain these in a list keyed by the consoleHandle until
+ * the queryComplete() gets sent.
+ */
+ private Map<String, List<QmfAgentData>> _queryResults = new ConcurrentHashMap<String, List<QmfAgentData>>();
+
+ // QMF API Methods
+ // ********************************************************************************************************
+
+ /**
+ * Constructor that provides defaults for name, domain and heartbeat interval and takes a Notifier/Listener.
+ *
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread.
+ * <p>
+ * This API may be simpler and more convenient than the QMF2 Notifier API for many applications.
+ */
+ public AgentExternal(final QmfCallback notifier) throws QmfException
+ {
+ super(null, null, notifier, 30);
+ }
+
+ /**
+ * Constructor that provides defaults for name and domain and takes a Notifier/Listener
+ *
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread.
+ * <p>
+ * This API may be simpler and more convenient than the QMF2 Notifier API for many applications.
+ * @param interval is the heartbeat interval in seconds.
+ */
+ public AgentExternal(final QmfCallback notifier, final int interval) throws QmfException
+ {
+ super(null, null, notifier, interval);
+ }
+
+ /**
+ * Main constructor, creates a Agent, but does NOT start it, that requires us to do setConnection()
+ *
+ * @param name If a name is supplied, it must be unique across all attached to the AMQP bus under the given domain.
+ * <p>
+ * The name must comprise three parts separated by colons: <pre>&lt;vendor&gt;:&lt;product&gt;[:&lt;instance&gt;]</pre>
+ * where the vendor is the Agent vendor name, the product is the Agent product itself and the instance is a UUID
+ * representing the running instance.
+ * <p>
+ * If the instance is not supplied then a random UUID will be generated.
+ * @param domain the QMF "domain".
+ * <p>
+ * A QMF address is composed of two parts - an optional domain string, and a mandatory name string
+ * <pre>"qmf.&lt;domain-string&gt;.direct/&lt;name-string&gt;"</pre>
+ * The domain string is used to construct the name of the AMQP exchange to which the component's name string will
+ * be bound. If not supplied, the value of the domain defaults to "default".
+ * <p>
+ * Both Agents and Components must belong to the same domain in order to communicate.
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread.
+ * <p>
+ * This API may be simpler and more convenient than the QMF2 Notifier API for many applications.
+ * @param interval is the heartbeat interval in seconds.
+ */
+ public AgentExternal(final String name, final String domain,
+ final QmfCallback notifier, final int interval) throws QmfException
+ {
+ super(name, domain, notifier, interval);
+ }
+
+ /**
+ * We override the base Class addObject() to throw an Exception as addObject() is used to populate the
+ * <b>internal</b> store.
+ */
+ @Override
+ public void addObject(final QmfAgentData object) throws QmfException
+ {
+ throw new QmfException("Cannot call addObject() on AgentExternal as this method is used to populate the internal object store");
+ }
+
+ /**
+ * Indicate to QMF that the named object is available to be managed. Once this method returns, the agent will
+ * service requests from consoles referencing this data.
+ *
+ * @param objectName the name of the QmfAgentData being managed.
+ * @return a new ObjectId based on the objectName passed as a parameter.
+ */
+ public ObjectId allocObjectId(final String objectName)
+ {
+ return new ObjectId(getName(), objectName, getEpoch());
+ }
+
+ /**
+ * Indicate to QMF that the named object is no longer available to be managed.
+ *
+ * @param objectName the name of the QmfAgentData being managed.
+ */
+ public void freeObjectId(final String objectName)
+ {
+ // Null implementation. It's not really clear that there's anything useful that the Agent needs to do here
+ }
+
+ /**
+ * Send a managed object in reply to a received query. Note that ownership of the object instance is returned to
+ * the caller on return from this call.
+ *
+ * @param handle the handle from the WorkItem.
+ * @param object a managed QmfAgentData object.
+ */
+ public void queryResponse(final Handle handle, final QmfAgentData object)
+ {
+ String index = handle.getCorrelationId();
+ List<QmfAgentData> objects = _queryResults.get(index);
+ if (objects == null)
+ {
+ objects = new ArrayList<QmfAgentData>();
+ _queryResults.put(index, objects);
+ }
+ objects.add(object);
+ }
+
+ /**
+ * Indicate to the agent that the application has completed processing a query request.
+ * Zero or more calls to the queryResponse() method should be invoked before calling query_complete().
+ * If the query should fail - for example, due to authentication error - the result should be set to a
+ * non-zero error code ?TBD?.
+ *
+ * @param handle the handle from the WorkItem.
+ * @param statusCode if this is non zero it indicates that the query failed.
+ */
+ public void queryComplete(final Handle handle, final int statusCode)
+ {
+ String index = handle.getCorrelationId();
+ List<QmfAgentData> objects = _queryResults.get(index);
+ if (objects != null)
+ {
+ List<Map> results = new ArrayList<Map>(objects.size());
+ for (QmfAgentData object : objects)
+ {
+ results.add(object.mapEncode());
+ }
+
+ // Send the response back to the Console
+ queryResponse(handle, results, "_data");
+ _queryResults.remove(index);
+ }
+ }
+
+ /**
+ * This has actually been implemented in the base Agent class as it's useful there too.
+ *
+ * If the subscription request is successful, the Agent application must provide a unique subscriptionId.
+ * If replying to a sucessful subscription refresh, the original subscriptionId must be supplied.
+ * If the subscription or refresh fails, the subscriptionId should be set to null and error may be set to
+ * an application-specific QmfData instance that describes the error.
+ * Should a refresh request fail, the consoleHandle may be set to null if unknown.
+ *
+ * @param handle the handle from the WorkItem
+ * @param consoleHandle the console reply handle
+ * @param subscriptionId a unique handle for the subscription supplied by the Agent
+ * @param lifetime should be set to the duration of the subscription in seconds.
+ * @param publishInterval should be set to the time interval in seconds between successive publications
+ * on this subscription.
+ * @param error an application-specific QmfData instance that describes the error.
+ */
+ //public void subscriptionResponse(Handle handle, Handle consoleHandle, String subscriptionId, long lifetime, long
+ // publishInterval, QmfData error)
+
+ /**
+ * Send a list of updated subscribed data to the Console.
+ *
+ * Note that the base Agent class contains a sendSubscriptionIndicate() for data that is already mapEncoded()
+ * To be honest AgentExternal Agents that happen to implement the SubscriptionProxy interface which reuses the
+ * Internal Agent Subscription code will almost certainly call the base class sendSubscriptionIndicate() as the
+ * SubscriptionProxy sendSubscriptionIndicate() has the same signature.
+ *
+ * @param handle the console reply handle.
+ * @param objects a list of subscribed data in QmfAgentData encoded form.
+ */
+ public void subscriptionIndicate(final Handle handle, final List<QmfAgentData> objects)
+ {
+ List<Map> results = new ArrayList<Map>(objects.size());
+ for (QmfAgentData object : objects)
+ {
+ results.add(object.mapEncode());
+ }
+ sendSubscriptionIndicate(handle, results);
+ }
+
+ /**
+ * Acknowledge a Subscription Cancel WorkItem.
+ *
+ * @param handle the handle from the WorkItem.
+ * @param consoleHandle the console reply handle.
+ */
+ public void subscriptionCancel(final Handle handle, final String consoleHandle)
+ {
+ // Null implementation, there isn't really much that needs to be done after cancelling a Subscription
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallParams.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallParams.java
new file mode 100644
index 0000000000..1f69709225
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallParams.java
@@ -0,0 +1,123 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+
+/**
+ * This class contains the values passed by the Agent class to the Agent implementation within the MethodCallWorkItem.
+ * <p>
+ * It contains information that is needed by the Agent implementation to identify the object on which the method.
+ * is to be called via getObjectId(), the name of the method to be invoked via getName() and the arguments of the
+ * method via getArgs().
+ *
+ * @author Fraser Adams
+ */
+
+public final class MethodCallParams
+{
+ private final String _name;
+ private final ObjectId _objectId;
+ private final QmfData _args;
+ private final String _userId;
+
+ /**
+ * Construct MethodCallParams.
+ *
+ * @param m the Map used to populate the WorkItem's parameters.
+ */
+ public MethodCallParams(final Map m)
+ {
+ _name = QmfData.getString(m.get("_method_name"));
+
+ Map oid = (Map)m.get("_object_id");
+ _objectId = (oid == null) ? null : new ObjectId(oid);
+
+ Map args = (Map)m.get("_arguments");
+ if (args == null)
+ {
+ _args = null;
+ }
+ else
+ {
+ _args = new QmfData(args);
+ _args.setSubtypes((Map)m.get("_subtypes"));
+ }
+ _userId = QmfData.getString(m.get("_user_id"));
+ }
+
+ /**
+ * Return a string containing the name of the method call.
+ * @return a string containing the name of the method call.
+ */
+ public String getName()
+ {
+ return _name;
+ }
+
+ /**
+ * Return the identifier for the object on which this method needs to be invoked.
+ * @return the identifier for the object on which this method needs to be invoked.
+ * <p>
+ * Returns null iff there is no associated object (a method call against the agent itself).
+ */
+ public ObjectId getObjectId()
+ {
+ return _objectId;
+ }
+
+ /**
+ * Return a map of input arguments for the method.
+ * @return a map of input arguments for the method.
+ * <p>
+ * Arguments are in "name"=&lt;value&gt; pairs. Returns null if no arguments are supplied.
+ */
+ public QmfData getArgs()
+ {
+ return _args;
+ }
+
+ /**
+ * Return authenticated user id of caller if present, else null.
+ * @return authenticated user id of caller if present, else null.
+ */
+ public String getUserId()
+ {
+ return _userId;
+ }
+
+ /**
+ * Helper/debug method to list the properties and their type.
+ */
+ public void listValues()
+ {
+ System.out.println("MethodCallParams:");
+ System.out.println("name: " + _name);
+ System.out.println("objectId: " + _objectId);
+ System.out.println("args: " + _args);
+ System.out.println("userId: " + _userId);
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallWorkItem.java
new file mode 100644
index 0000000000..b83262d550
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/MethodCallWorkItem.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * METHOD_CALL: The METHOD_CALL WorkItem describes a method call that must be serviced by the application on
+ * behalf of this Agent.
+ *
+ * The getParams() method of a METHOD_CALL WorkItem will return an instance of the MethodCallParams class.
+ *
+ * Use MethodCallWorkItem to enable neater access
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class MethodCallWorkItem extends WorkItem
+{
+ /**
+ * Construct a MethodCallWorkItem. Convenience constructor not in API
+ *
+ * @param handle the reply handle.
+ * @param params the MethodCallParams used to populate the WorkItem's param.
+ */
+ public MethodCallWorkItem(final Handle handle, final MethodCallParams params)
+ {
+ super(WorkItemType.METHOD_CALL, handle, params);
+ }
+
+ /**
+ * Return the MethodCallParams stored in the params Map.
+ * @return the MethodCallParams stored in the params Map.
+ */
+ public MethodCallParams getMethodCallParams()
+ {
+ return (MethodCallParams)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QmfAgentData.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QmfAgentData.java
new file mode 100644
index 0000000000..560ed9e975
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QmfAgentData.java
@@ -0,0 +1,364 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfManaged;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+
+/**
+ * The Agent manages the data it represents by the QmfAgentData class - a derivative of the QmfData class.
+ * <p>
+ * The Agent is responsible for managing the values of the properties within the object, as well as servicing
+ * the object's method calls. Unlike the Console, the Agent has full control of the state of the object.
+ * <p>
+ * In most cases, for efficiency, it is expected that Agents would <i>actually</i> manage objects that are subclasses of
+ * QmfAgentData and maintain subclass specific properties as primitives, only actually explicitly setting the
+ * underlying Map properties via setValue() etc. when the object needs to be "serialised". This would most
+ * obviously be done by extending the mapEncode() method (noting that it's important to call QmfAgentData's mapEncode()
+ * first via super.mapEncode(); as this will set the state of the underlying QmfData).
+ * <p>
+ * This class provides a number of methods aren't in the QMF2 API per se, but they are used to manage the association
+ * between a managed object and any subscriptions that might be interested in it.
+ * <p>
+ * The diagram below shows the relationship between the Subscription and QmfAgentData.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ * <p>
+ * In particular the QmfAgentData maintains references to active subscriptions to allow agents to asynchronously
+ * push data to subscribing Consoles immediately that data becomes available.
+ * <p>
+ * The update() method indicates that the object's state has changed and the publish() method <b>immediately</b> sends
+ * the new state to any subscription.
+ * <p>
+ * The original intention was to "auto update" by calling these from the setValue() method. Upon reflection this
+ * seems a bad idea, as in many cases there may be several properties that an Agent may wish to change which would
+ * lead to unnecessary calls to currentTimeMillis(), but also as theSubscription update is run via a TimerTask it is
+ * possible that an update indication could get sent part way through setting an object's overall state.
+ * Similarly calling the publish() method directly from setValue() would force an update indication on partial changes
+ * of state, which is generally not the desired behaviour.
+ * @author Fraser Adams
+ */
+public class QmfAgentData extends QmfManaged implements Comparable<QmfAgentData>
+{
+ private long _updateTimestamp;
+ private long _createTimestamp;
+ private long _deleteTimestamp;
+ private String _compareKey = null;
+
+ /**
+ * This Map is used to look up Subscriptions that are interested in this data by SubscriptionId
+ */
+ private Map<String, Subscription> _subscriptions = new ConcurrentHashMap<String, Subscription>();
+
+ /**
+ * Construct a QmfAgentData object of the type described by the given SchemaObjectClass.
+ *
+ * @param schema the schema describing the type of this QmfAgentData object.
+ */
+ public QmfAgentData(final SchemaObjectClass schema)
+ {
+ long currentTime = System.currentTimeMillis()*1000000l;
+ _updateTimestamp = currentTime;
+ _createTimestamp = currentTime;
+ _deleteTimestamp = 0;
+ setSchemaClassId(schema.getClassId());
+ }
+
+ /**
+ * Return the creation timestamp.
+ * @return the creation timestamp. Timestamps are recorded in nanoseconds since the epoch
+ */
+ public final long getCreateTime()
+ {
+ return _createTimestamp;
+ }
+
+ /**
+ * Return the update timestamp.
+ * @return the update timestamp. Timestamps are recorded in nanoseconds since the epoch
+ */
+ public final long getUpdateTime()
+ {
+ return _updateTimestamp;
+ }
+
+ /**
+ * Return the deletion timestamp.
+ * @return the deletion timestamp, or zero if not deleted. Timestamps are recorded in nanoseconds since the epoch
+ */
+ public final long getDeleteTime()
+ {
+ return _deleteTimestamp;
+ }
+
+ /**
+ * Return true if deletion timestamp not zero.
+ * @return true if deletion timestamp not zero.
+ */
+ public final boolean isDeleted()
+ {
+ return getDeleteTime() != 0;
+ }
+
+ /**
+ * Mark the object as deleted by setting the deletion timestamp to the current time.
+ * <p>
+ * This method alse publishes the deleted object to any listening Subscription then removes references to the
+ * Subscription.
+ * <p>
+ * When this method returns the object should be ready for reaping.
+ */
+ public final void destroy()
+ {
+ _deleteTimestamp = System.currentTimeMillis()*1000000l;
+ _updateTimestamp = System.currentTimeMillis()*1000000l;
+ publish();
+ _subscriptions.clear();
+ }
+
+ /**
+ * Add the delta to the property.
+ *
+ * @param name the name of the property being modified.
+ * @param delta the value being added to the property.
+ */
+ public final synchronized void incValue(final String name, final long delta)
+ {
+ long value = getLongValue(name);
+ value += delta;
+ setValue(name, value);
+ }
+
+ /**
+ * Add the delta to the property.
+ *
+ * @param name the name of the property being modified.
+ * @param delta the value being added to the property.
+ */
+ public final synchronized void incValue(final String name, final double delta)
+ {
+ double value = getDoubleValue(name);
+ value += delta;
+ setValue(name, value);
+ }
+
+ /**
+ * Subtract the delta from the property.
+ *
+ * @param name the name of the property being modified.
+ * @param delta the value being subtracted from the property.
+ */
+ public final synchronized void decValue(final String name, final long delta)
+ {
+ long value = getLongValue(name);
+ value -= delta;
+ setValue(name, value);
+ }
+
+ /**
+ * Subtract the delta from the property.
+ *
+ * @param name the name of the property being modified.
+ * @param delta the value being subtracted from the property.
+ */
+ public final synchronized void decValue(final String name, final double delta)
+ {
+ double value = getDoubleValue(name);
+ value -= delta;
+ setValue(name, value);
+ }
+
+ // The following methods aren't in the QMF2 API per se, but they are used to manage the association between
+ // a managed object and any subscriptions that might be interested in it.
+
+ /**
+ * Return the Subscription with the specified ID.
+ * @return the Subscription with the specified ID.
+ */
+ public final Subscription getSubscription(final String subscriptionId)
+ {
+ return _subscriptions.get(subscriptionId);
+ }
+
+ /**
+ * Add a new Subscription reference.
+ * @param subscriptionId the ID of the Subscription being added.
+ * @param subscription the Subscription being added.
+ */
+ public final void addSubscription(final String subscriptionId, final Subscription subscription)
+ {
+ _subscriptions.put(subscriptionId, subscription);
+ }
+
+ /**
+ * Remove a Subscription reference.
+ * @param subscriptionId the ID of the Subscription being removed.
+ */
+ public final void removeSubscription(final String subscriptionId)
+ {
+ _subscriptions.remove(subscriptionId);
+ }
+
+
+ /**
+ * Set the _updateTimestamp to indicate (particularly to subscriptions) that the managed object has changed.
+ * <p>
+ * The update() method indicates that the object's state has changed and the publish() method <b>immediately</b> sends
+ * the new state to any subscription.
+ * <p>
+ * The original intention was to "auto update" by calling these from the setValue() method. Upon reflection this
+ * seems a bad idea, as in many cases there may be several properties that an Agent may wish to change which would
+ * lead to unnecessary calls to currentTimeMillis(), but also as the Subscription update is run via a TimerTask it
+ * is possible that an update indication could get sent part way through setting an object's overall state.
+ * Similarly calling the publish() method directly from setValue() would force an update indication on partial
+ * changes of state, which is generally not the desired behaviour.
+ */
+ public final void update()
+ {
+ _updateTimestamp = System.currentTimeMillis()*1000000l;
+ }
+
+ /**
+ * Iterate through any Subscriptions associated with this Object and force them to republish the Object's new state.
+ * <p>
+ * The update() method indicates that the object's state has changed and the publish() method <b>immediately</b> sends
+ * the new state to any subscription.
+ * <p>
+ * The original intention was to "auto update" by calling these from the setValue() method. Upon reflection this
+ * seems a bad idea, as in many cases there may be several properties that an Agent may wish to change which would
+ * lead to unnecessary calls to currentTimeMillis(), but also as the Subscription update is run via a TimerTask it
+ * is possible that an update indication could get sent part way through setting an object's overall state.
+ * Similarly calling the publish() method directly from setValue() would force an update indication on partial
+ * changes of state, which is generally not the desired behaviour.
+ */
+ public final void publish()
+ {
+ update();
+ if (getObjectId() == null)
+ { // If ObjectId is null the Object isn't yet Managed to we can't publish
+ return;
+ }
+
+ List<Map> results = new ArrayList<Map>();
+ results.add(mapEncode());
+ for (Map.Entry<String, Subscription> entry : _subscriptions.entrySet())
+ {
+ Subscription subscription = entry.getValue();
+ subscription.publish(results);
+ }
+ }
+
+ /**
+ * Return the underlying map.
+ * <p>
+ * In most cases, for efficiency, it is expected that Agents would <i>actually</i> manage objects that are
+ * subclasses of QmfAgentData and maintain subclass specific properties as primitives, only actually explicitly
+ * setting the underlying Map properties via setValue() etc. when the object needs to be "serialised". This would
+ * most obviously be done by extending the mapEncode() method (noting that it's important to call QmfAgentData's
+ * mapEncode() first via super.mapEncode(); as this will set the state of the underlying QmfData).
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("_values", super.mapEncode());
+ if (_subtypes != null)
+ {
+ map.put("_subtypes", _subtypes);
+ }
+ map.put("_schema_id", getSchemaClassId().mapEncode());
+ map.put("_object_id", getObjectId().mapEncode());
+ map.put("_update_ts", _updateTimestamp);
+ map.put("_create_ts", _createTimestamp);
+ map.put("_delete_ts", _deleteTimestamp);
+ return map;
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ super.listValues();
+ System.out.println("QmfAgentData:");
+ System.out.println("create timestamp: " + new Date(getCreateTime()/1000000l));
+ System.out.println("update timestamp: " + new Date(getUpdateTime()/1000000l));
+ System.out.println("delete timestamp: " + new Date(getDeleteTime()/1000000l));
+ }
+
+ // The following methods allow instances of QmfAgentData to be compared with each other and sorted.
+ // N.B. This behaviour is not part of the specified QmfAgentData, but it's quite useful for some Agents.
+
+ /**
+ * Set the key String to be used for comparing two QmfAgentData instances. This is primarily used by the Agent
+ * to allow it to order Query results (e.g. for getObjects()).
+ * @param compareKey the String that we wish to use as a compare key.
+ */
+ public void setCompareKey(String compareKey)
+ {
+ _compareKey = compareKey;
+ }
+
+ /**
+ * If a compare key has been set then the QmfAgentData is sortable.
+ * @return true if a compare key has been set and the QmfAgentData is sortable otherwise return false.
+ */
+ public boolean isSortable()
+ {
+ return _compareKey != null;
+ }
+
+ /**
+ * Compare the compare key of this QmfAgentData with the specified other QmfAgentData.
+ * Compares the compare keys (which are Strings) lexicographically. The comparison is based on the Unicode
+ * value of each character in the strings.
+ * @param rhs the String to be compared.
+ * @return the value 0 if the argument string is equal to this string; a value less than 0 if this string is
+ * lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically
+ * greater than the string argument.
+ */
+ public int compareTo(QmfAgentData rhs)
+ {
+ if (_compareKey == null)
+ {
+ return 0;
+ }
+ else
+ {
+ return this._compareKey.compareTo(rhs._compareKey);
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QueryWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QueryWorkItem.java
new file mode 100644
index 0000000000..c714720bc5
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/QueryWorkItem.java
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * QUERY: The QUERY WorkItem describes a query that the application must service. The application should call the
+ * queryResponse() method for each object that satisfies the query. When complete, the application must call the
+ * queryComplete() method. If a failure occurs, the application should indicate the error to the agent by calling
+ * the query_complete() method with a description of the error.
+ *
+ * The getParams() method of a QUERY WorkItem will return an instance of the QmfQuery class.
+ *
+ * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's queryResponse()
+ * and queryComplete() methods.
+ * </pre>
+ * Note that the API is a bit sketchy on the description of the QUERY WorkItem and whereas most WorkItems seem to return
+ * defined classes for their getParams() it's not so obvious here. There's an implication that getParams() just returns
+ * QmfQuery, but it's not clear where the uset_id bit fits.
+ * <p>
+ * As the API doesn't define a "QueryParams" class I've not included one, but I've added a getUserId() method to
+ * QueryWorkItem, this is a bit inconsistent with the approach for the other WorkItems though.
+ *
+ * @author Fraser Adams
+ */
+
+public final class QueryWorkItem extends WorkItem
+{
+ /**
+ * Construct a QueryWorkItem. Convenience constructor not in API.
+ *
+ * @param handle the reply handle.
+ * @param params the QmfQuery used to populate the WorkItem's param.
+ */
+ public QueryWorkItem(final Handle handle, final QmfQuery params)
+ {
+ super(WorkItemType.QUERY, handle, params);
+ }
+
+ /**
+ * Return the QmfQuery stored in the params Map.
+ * @return the QmfQuery stored in the params Map.
+ */
+ public QmfQuery getQmfQuery()
+ {
+ return (QmfQuery)getParams();
+ }
+
+ /**
+ * Return authenticated user id of caller if present, else null.
+ * @return authenticated user id of caller if present, else null.
+ */
+ public String getUserId()
+ {
+ Map map = getQmfQuery().mapEncode();
+ return (String)map.get("_user_id");
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeParams.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeParams.java
new file mode 100644
index 0000000000..475b378b75
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeParams.java
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfData;
+
+/**
+ * Holds the information contained in a resubscription request made by a Console to an Agent
+ *
+ * @author Fraser Adams
+ */
+public final class ResubscribeParams extends QmfData
+{
+ /**
+ * Construct ResubscribeParams.
+ *
+ * @param m the Map used to populate the ResubscribeParams state.
+ */
+ public ResubscribeParams(final Map m)
+ {
+ super(m);
+ }
+
+ /**
+ * Return a SubscriptionId object.
+ * @return a SubscriptionId object.
+ */
+ public String getSubscriptionId()
+ {
+ if (hasValue("_subscription_id"))
+ {
+ return getStringValue("_subscription_id");
+ }
+ return null;
+ }
+
+ /**
+ * Return the requested lifetime for the subscription.
+ * @return the requested lifetime for the subscription. Zero if the previous interval should be used.
+ */
+ public long getLifetime()
+ {
+ return getLongValue("_duration");
+ }
+
+ /**
+ * Return authenticated user id of caller if present, else null.
+ * @return authenticated user id of caller if present, else null.
+ */
+ public String getUserId()
+ {
+ return getStringValue("_user_id");
+ }
+}
+
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeRequestWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeRequestWorkItem.java
new file mode 100644
index 0000000000..298e499c1c
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/ResubscribeRequestWorkItem.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * RESUBSCRIBE_REQUEST: The RESUBSCRIBE_REQUEST is sent by a Console to renew an existing subscription. The Console may
+ * request a new duration for the subscription, otherwise the previous lifetime interval is repeated.
+ *
+ * The getParams() method of a RESUBSCRIBE_REQUEST WorkItem will return an instance of the
+ * ResubscribeParams class.
+ *
+ * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's
+ * subscriptionResponse() method.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class ResubscribeRequestWorkItem extends WorkItem
+{
+ /**
+ * Construct a ResubscribeRequestWorkItem. Convenience constructor not in API.
+ *
+ * @param handle the reply handle.
+ * @param params the ResubscribeParams used to populate the WorkItem's param.
+ */
+ public ResubscribeRequestWorkItem(final Handle handle, final ResubscribeParams params)
+ {
+ super(WorkItemType.RESUBSCRIBE_REQUEST, handle, params);
+ }
+
+ /**
+ * Return the ResubscribeParams stored in the params Map.
+ * @return the ResubscribeParams stored in the params Map.
+ */
+ public ResubscribeParams getResubscribeParams()
+ {
+ return (ResubscribeParams)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribableAgent.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribableAgent.java
new file mode 100644
index 0000000000..df9c92abca
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribableAgent.java
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+// Misc Imports
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.QmfQuery;
+
+/**
+ * This interface provides a number of methods that are called by a Subscription in order to interact with an
+ * Agent or an Agent's managed data.
+ * <p>
+ * The purpose of this interface is primarily about removing a circular dependency between Subscription and Agent
+ * so the Subscription doesn't invoke these methods on an Agent instance, rather it invokes them on a
+ * SubscribeableAgent instance.
+ * <p>
+ * The following diagram illustrates the interactions between the Agent, Subscription and SubscribableAgent.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ *
+ * @author Fraser Adams
+ */
+public interface SubscribableAgent
+{
+ /**
+ * Send a list of updated subscribed data to the Console.
+ *
+ * @param handle the console reply handle
+ * @param results a list of subscribed data in Map encoded form
+ */
+ public void sendSubscriptionIndicate(Handle handle, List<Map> results);
+
+ /**
+ * This method evaluates a QmfQuery over the Agent's data on behalf of a Subscription
+ *
+ * @param query the QmfQuery that the Subscription wants to be evaluated over the Agent's data
+ * @return a List of QmfAgentData objects that match the specified QmfQuery
+ */
+ public List<QmfAgentData> evaluateQuery(QmfQuery query);
+
+ /**
+ * This method is called by the Subscription to tell the SubscriberProxy that the Subscription has been cancelled.
+ *
+ * @param subscription the Subscription that has been cancelled and is requesting removal.
+ */
+ public void removeSubscription(Subscription subscription);
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribeRequestWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribeRequestWorkItem.java
new file mode 100644
index 0000000000..a28faa8812
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscribeRequestWorkItem.java
@@ -0,0 +1,69 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * SUBSCRIBE_REQUEST: The SUBSCRIBE_REQUEST WorkItem provides a query that the agent application must periodically
+ * publish until the subscription is cancelled or expires. On receipt of this WorkItem, the
+ * application should call the Agent subscriptionResponse() method to acknowledge the request.
+ * On each publish interval, the application should call Agent subscriptionIndicate(), passing a
+ * list of the objects that satisfy the query. The subscription remains in effect until an
+ * UNSUBSCRIBE_REQUEST WorkItem for the subscription is received, or the subscription expires.
+ *
+ * The getParams() method of a QUERY WorkItem will return an instance of the SubscriptionParams class.
+ *
+ * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's
+ * subscriptionResponse() method.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class SubscribeRequestWorkItem extends WorkItem
+{
+ /**
+ * Construct a SubscribeRequestWorkItem. Convenience constructor not in API
+ *
+ * @param handle the reply handle
+ * @param params the SubscriptionParams used to populate the WorkItem's param
+ */
+ public SubscribeRequestWorkItem(final Handle handle, final SubscriptionParams params)
+ {
+ super(WorkItemType.SUBSCRIBE_REQUEST, handle, params);
+ }
+
+ /**
+ * Return the SubscriptionParams stored in the params Map.
+ * @return the SubscriptionParams stored in the params Map.
+ */
+ public SubscriptionParams getSubscriptionParams()
+ {
+ return (SubscriptionParams)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Subscription.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Subscription.java
new file mode 100644
index 0000000000..e6800a9a41
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/Subscription.java
@@ -0,0 +1,280 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TimerTask;
+import java.util.UUID;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+
+/**
+ * This TimerTask represents a running Subscription on the Agent.
+ * <p>
+ * The main reason we have Subscriptions as TimerTasks is to enable proper cleanup of the references stored in
+ * the _subscriptions Map when the Subscription expires. The timer also causes QmfAgenData that have been updated
+ * since the last interval to be published.
+ * <p>
+ * The following diagram illustrates the Subscription relationships with the Agent and QmfAgentData.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ * @author Fraser Adams
+ */
+public final class Subscription extends TimerTask
+{
+ private static final Logger _log = LoggerFactory.getLogger(Subscription.class);
+
+ // Duration is the time (in seconds) the Subscription is active before it automatically expires unless refreshed
+ private static final int DEFAULT_DURATION = 300;
+ private static final int MAX_DURATION = 3600;
+ private static final int MIN_DURATION = 10;
+
+ // Interval is the period (in milliseconds) between subscription ubdates.
+ private static final int DEFAULT_INTERVAL = 30000;
+ private static final int MIN_INTERVAL = 1000;
+
+ private SubscribableAgent _agent;
+ private long _startTime = System.currentTimeMillis();
+ private long _lastUpdate = _startTime*1000000l;
+ private String _subscriptionId;
+ private Handle _consoleHandle;
+ private QmfQuery _query;
+ private long _duration = 0;
+ private long _interval = 0;
+
+ /**
+ * Tells the SubscribableAgent to send the results to the Console via a subscription indicate message.
+ *
+ * @param results the list of mapEncoded QmfAgentData that currently match the query associated with this
+ * Subscription.
+ */
+ protected void publish(List<Map> results)
+ {
+ _agent.sendSubscriptionIndicate(_consoleHandle, results);
+ _lastUpdate = System.currentTimeMillis()*1000000l;
+ }
+
+ /**
+ * Construct a new Subscription.
+ * @param agent the SubscribableAgent to which this Subscription is associated.
+ * @param params the SubscriptionParams object that contains the information needed to create a Subscription.
+ */
+ public Subscription(SubscribableAgent agent, SubscriptionParams params) throws QmfException
+ {
+ _agent = agent;
+ _subscriptionId = UUID.randomUUID().toString();
+ _consoleHandle = params.getConsoleHandle();
+ _query = params.getQuery();
+ setDuration(params.getLifetime());
+ setInterval(params.getPublishInterval());
+
+ _log.debug("Creating Subscription {}, duration = {}, interval = {}", new Object[] {_subscriptionId, _duration, _interval});
+ }
+
+ /**
+ * This method gets called periodically by the Timer scheduling this TimerTask.
+ * <p>
+ * First a check is made to see if the Subscription has expired, if it has then it is cancelled.
+ * <p>
+ * If the Subscription isn't cancelled the Query gets evaluated against all registered objects and any that match
+ * which are new to the Subscription or have changed since the last update get published.
+ */
+ public void run()
+ {
+ long elapsed = (long)Math.round((System.currentTimeMillis() - _startTime)/1000.0f);
+ if (elapsed >= _duration)
+ {
+ _log.debug("Subscription {} has expired, removing", _subscriptionId);
+ // The Subscription has expired so cancel it
+ cancel();
+ }
+ else
+ {
+ List<QmfAgentData> objects = _agent.evaluateQuery(_query);
+ List<Map> results = new ArrayList<Map>(objects.size());
+ for (QmfAgentData object : objects)
+ {
+ if (object.getSubscription(_subscriptionId) == null)
+ {
+ // The object is new to this Subscription so publish it
+ object.addSubscription(_subscriptionId, this);
+ results.add(object.mapEncode());
+ }
+ else
+ {
+ // If the object has had update() called since last Subscription update publish it.
+ // Note that in many cases an Agent might call publish() on a managed object rather than
+ // update() which immediately forces a data indication to be sent to the subscriber on
+ // the Console.
+ if (object.getUpdateTime() > _lastUpdate)
+ {
+ results.add(object.mapEncode());
+ }
+ }
+ }
+
+ if (results.size() > 0)
+ {
+ publish(results);
+ }
+ }
+ }
+
+ /**
+ * Refresh the subscription by zeroing its elapsed time.
+ *
+ * @param resubscribeParams the ResubscribeParams passed by the Console potentially containing new duration
+ * information.
+ */
+ public void refresh(ResubscribeParams resubscribeParams)
+ {
+ _log.debug("Refreshing Subscription {}", _subscriptionId);
+ _startTime = System.currentTimeMillis();
+ setDuration(resubscribeParams.getLifetime());
+ }
+
+ /**
+ * Cancel the Subscription, tidying references up and cancelling the TimerTask.
+ */
+ @Override
+ public boolean cancel()
+ {
+ _log.debug("Cancelling Subscription {}", _subscriptionId);
+ // This Subscription is about to be deleted, remove it from any Objects that may be referencing it.
+ List<QmfAgentData> objects = _agent.evaluateQuery(_query);
+ for (QmfAgentData object : objects)
+ {
+ object.removeSubscription(_subscriptionId);
+ }
+
+ _agent.removeSubscription(this);
+ return super.cancel(); // Cancel the TimerTask
+ }
+
+ /**
+ * Return the SubscriptionId of this subscription.
+ * @return the SubscriptionId of this subscription.
+ */
+ public String getSubscriptionId()
+ {
+ return _subscriptionId;
+ }
+
+ /**
+ * Return the consoleHandle of this subscription.
+ * @return the consoleHandle of this subscription.
+ */
+ public Handle getConsoleHandle()
+ {
+ return _consoleHandle;
+ }
+
+ /**
+ * Set the Subscription lifetime in seconds. If the value passed to this method is zero the duration gets
+ * set to the Agent's DEFAULT_DURATION is the duration has not already been set, if the duration has already
+ * been set passing in a zero value has no effect on the duration.
+ * If the value passed is non-zero the duration passed gets restricted between the Agent's MIN_DURATION
+ * and MAX_DURATION.
+ *
+ * @param duration the new Subscription lifetime in seconds.
+ */
+ public void setDuration(long duration)
+ {
+ if (duration == 0)
+ {
+ if (_duration == 0)
+ {
+ _duration = DEFAULT_DURATION;
+ }
+ return;
+ }
+ else
+ {
+ if (duration > MAX_DURATION)
+ {
+ duration = MAX_DURATION;
+ }
+ else if (duration < MIN_DURATION)
+ {
+ duration = MIN_DURATION;
+ }
+ }
+ _duration = duration;
+ }
+
+ /**
+ * Return the current Subscription lifetime value in seconds.
+ * @return the current Subscription lifetime value in seconds.
+ */
+ public long getDuration()
+ {
+ return _duration;
+ }
+
+ /**
+ * Set the Subscription refresh interval in seconds. If the value passed to this method is zero the interval gets
+ * set to the Agent's DEFAULT_INTERVAL otherwise the interval passed gets restricted to be >= the Agent's
+ * MIN_INTERVAL.
+ *
+ * @param interval the time (in milliseconds) between periodic updates of data in this Subscription.
+ */
+ public void setInterval(long interval)
+ {
+ if (interval == 0)
+ {
+ interval = DEFAULT_INTERVAL;
+ }
+ else if (interval < MIN_INTERVAL)
+ {
+ interval = MIN_INTERVAL;
+ }
+ _interval = interval;
+ }
+
+ /**
+ * Return The time (in milliseconds) between periodic updates of data in this Subscription.
+ * @return The time (in milliseconds) between periodic updates of data in this Subscription.
+ */
+ public long getInterval()
+ {
+ return _interval;
+ }
+
+ /**
+ * Return The Subscription's QmfQuery.
+ * @return The Subscription's QmfQuery.
+ */
+ public QmfQuery getQuery()
+ {
+ return _query;
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscriptionParams.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscriptionParams.java
new file mode 100644
index 0000000000..1cc2a9a5d1
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/SubscriptionParams.java
@@ -0,0 +1,102 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+
+/**
+ * Holds the information contained in a subscription request made by a Console to an Agent
+ *
+ * @author Fraser Adams
+ */
+public final class SubscriptionParams extends QmfData
+{
+ private final Handle _consoleHandle;
+
+ /**
+ * Construct SubscriptionParams.
+ *
+ * @param handle the handle that the console uses to identify this subscription.
+ * @param m the Map used to populate the SubscriptionParams state.
+ */
+ public SubscriptionParams(final Handle handle, final Map m)
+ {
+ super(m);
+ _consoleHandle = handle;
+ }
+
+ /**
+ * Return the handle that the console uses to identify this subscription.
+ * @return the handle that the console uses to identify this subscription.
+ * <p>
+ * This handle must be passed along with every published update from the Agent.
+ */
+ public Handle getConsoleHandle()
+ {
+ return _consoleHandle;
+ }
+
+ /**
+ * Return the QmfQuery object associated with the SubscriptionParams.
+ * @return the QmfQuery object associated with the SubscriptionParams.
+ */
+ public QmfQuery getQuery() throws QmfException
+ {
+ return new QmfQuery((Map)getValue("_query"));
+ }
+
+ /**
+ * Return the requested time interval in seconds for updates.
+ * @return the requested time interval in seconds for updates. Zero if the Agent's default interval should be used.
+ */
+ public long getPublishInterval()
+ {
+ return getLongValue("_interval");
+ }
+
+ /**
+ * Return the requested lifetime for the subscription.
+ * @return the requested lifetime for the subscription. Zero if the Agent's default subscription lifetime
+ * should be used.
+ */
+ public long getLifetime()
+ {
+ return getLongValue("_duration");
+ }
+
+ /**
+ * Return authenticated user id of caller if present, else null.
+ * @return authenticated user id of caller if present, else null.
+ */
+ public String getUserId()
+ {
+ return getStringValue("_user_id");
+ }
+}
+
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/UnsubscribeRequestWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/UnsubscribeRequestWorkItem.java
new file mode 100644
index 0000000000..fc8d973356
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/UnsubscribeRequestWorkItem.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.qmf2.agent;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * UNSUBSCRIBE_REQUEST: The UNSUBSCRIBE_REQUEST is sent by a Console to terminate an existing subscription. The Agent
+ * application should terminate the given subscription if it exists, and cancel sending any further
+ * updates against it.
+ *
+ * The getParams() method of a UNSUBSCRIBE_REQUEST WorkItem will return a String holding the
+ * subscriptionId
+ *
+ * The getHandle() method returns null.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class UnsubscribeRequestWorkItem extends WorkItem
+{
+ /**
+ * Construct an UnsubscribeRequestWorkItem. Convenience constructor not in API
+ *
+ * @param params the ResubscribeParams used to populate the WorkItem's param
+ */
+ public UnsubscribeRequestWorkItem(final String params)
+ {
+ super(WorkItemType.UNSUBSCRIBE_REQUEST, null, params);
+ }
+
+ /**
+ * Return the subscriptionId String stored in the params Map.
+ * @return the subscriptionId String stored in the params Map.
+ */
+ public String getSubscriptionId()
+ {
+ return (String)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfData.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfData.png
new file mode 100644
index 0000000000..2665803e39
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfData.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfEventListenerModel.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfEventListenerModel.png
new file mode 100644
index 0000000000..26a5f71b56
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfEventListenerModel.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfQuery.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfQuery.png
new file mode 100644
index 0000000000..9e471a08c0
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/QmfQuery.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Schema.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Schema.png
new file mode 100644
index 0000000000..b0277f4fc5
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Schema.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Subscriptions.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Subscriptions.png
new file mode 100644
index 0000000000..d43370e4ef
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/Subscriptions.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/WorkQueueEventModel.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/WorkQueueEventModel.png
new file mode 100644
index 0000000000..fc2a722985
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/agent/doc-files/WorkQueueEventModel.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/AMQPMessage.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/AMQPMessage.java
new file mode 100644
index 0000000000..94b539c0b3
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/AMQPMessage.java
@@ -0,0 +1,309 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// JMS Imports
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageFormatException;
+import javax.jms.Session;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+
+// Need the following to decode and encode amqp/list messages
+import java.nio.ByteBuffer;
+import org.apache.qpid.transport.codec.BBDecoder;
+import org.apache.qpid.transport.codec.BBEncoder;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfData;
+
+/**
+ * Provides static helper methods for encoding and decoding "amqp/list" and "amqp/map" ContentTypes.
+ *<p>
+ * Unfortunately the encoding of amqp/map and amqp/list messages is not as useful as it might be in the
+ * Qpid JMS runtime. amqp/list messages don't <i>actually</i> have a useful encoding in Qpid JMS, so we have to
+ * fake it in this class by encoding/decoding java.util.List objects into a JMS BytesMessage and setting
+ * the ContentType to "amqp/list".
+ *<p>
+ * Whilst amqp/map messages are encoded as JMS MapMessage this isn't necessarily the most useful format as
+ * MapMessage does not conform to the java.util.Map interface. As QMF methods returning lists return lists
+ * of java.util.Map there's a bit of an inconsistency of type that getMap() resolves.
+ *
+ * @author Fraser Adams
+ */
+public final class AMQPMessage
+{
+ /**
+ * Make constructor private at this class provides a set of static helper methods and doesn't need instantiated.
+ */
+ private AMQPMessage()
+ {
+ }
+
+ /**
+ * This method exposes the AMQP Content-Type from a JMS Message. This has been put into an accessor
+ * method because some evil hackery has to take place to set the Content-Type as no pure JMS API
+ * property currently gets mapped to Content-Type, so we have to cast to AbstractJMSMessage.
+ *
+ * @param message a JMS Message.
+ * @return the AMQP Content-Type e.g. amqp/list, amqp/map etc.
+ */
+ public static String getContentType(final Message message)
+ {
+ return ((org.apache.qpid.client.message.AbstractJMSMessage)message).getContentType();
+ }
+
+ /**
+ * This method sets the AMQP Content-Type on a JMS Message. This has been put into a mutator
+ * method because some evil hackery has to take place to set the Content-Type as no pure JMS API
+ * property currently gets mapped to Content-Type, so we have to cast to AbstractJMSMessage.
+ *
+ * @param message a JMS Message.
+ * @param contentType the AMQP Content-Type that we'd like to set, e.g. amqp/list, amqp/map etc.
+ */
+ public static void setContentType(final Message message, String contentType)
+ {
+ ((org.apache.qpid.client.message.AbstractJMSMessage)message).setContentType(contentType);
+ }
+
+ /**
+ * Provides an abstracted way for client code to explicitly check if a Message is an AMQP List.
+ *
+ * @param message a JMS Message.
+ * @return true if the Message is an AMQP List, otherwise returns false.
+ */
+ public static boolean isAMQPList(final Message message)
+ {
+ if (getContentType(message).equals("amqp/list") || message instanceof BytesMessage)
+ {
+ // I *think* that the test for BytesMessage is actually redundant and that Content-Type would
+ // always have to be "amqp/list" for JMS to expose the Message as a BytesMessage but I've
+ // kept the test because pre Qpid 0.20 exposed lists as BytesMessage.
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Provides an abstracted way for client code to explicitly check if a Message is an AMQP Map.
+ *
+ * @param message a JMS Message.
+ * @return true if the Message is an AMQP Map, otherwise returns false.
+ */
+ public static boolean isAMQPMap(final Message message)
+ {
+ if (getContentType(message).equals("amqp/map") ||
+ (message instanceof MapMessage && !isAMQPList(message)))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Builds a java.util.Map from a JMS MapMessage.
+ * This is really a helper method to make code more homogenous as QmfData objects are constructed from Maps
+ * but JMS returns MapMessages which don't share a common interface. This method enumerates MapMessage
+ * Properties and Objects and stores them in a java.util.Map.
+ *
+ * @param message a JMS Message
+ * @return a java.util.Map containing the the properties extracted from the Message.
+ * <p>
+ * Note that this method copies the Message properties <b>and</b> the properties from the MapMessage Map.
+ * <p>
+ * This method also attempts to populate "_user_id" using the JMSXUserID property, however that's not as
+ * easy as it sounds!! There's a bug in AMQMessageDelegate_0_10.getStringProperty() whereby if the property
+ * is "JMSXUserID" it returns "new String(_messageProps.getUserId());" however if the client uses anonymous
+ * authentication _messageProps.getUserId() returns null. In order to get around this this class unfortunately
+ * has to delve inside "org.apache.qpid.client.message.AbstractJMSMessage".
+ */
+ public static Map<String, Object> getMap(final Message message) throws JMSException
+ {
+ if (message == null)
+ {
+ throw new MessageFormatException("Attempting to do AMQPMessage.getMap() on null Message");
+ }
+ else if (message instanceof MapMessage)
+ {
+ Map<String, Object> object = new HashMap<String, Object>();
+ MapMessage msg = (MapMessage)message;
+ for (Enumeration e = msg.getMapNames(); e.hasMoreElements();)
+ {
+ String key = (String)e.nextElement();
+ object.put(key, msg.getObject(key));
+ }
+
+ if (object.size() == 0)
+ { // If there is no MapMessage content return an empty Map.
+ return object;
+ }
+
+ // If there is MapMessage content include the Message properties in the returned Map.
+ for (Enumeration e = msg.getPropertyNames(); e.hasMoreElements();)
+ {
+ String prop = (String)e.nextElement();
+ object.put(prop, QmfData.getString(msg.getObjectProperty(prop)));
+ }
+
+ // Should be msg.getStringProperty("JMSXUserID"). See comments above for the reason behind this evil hack.
+ org.apache.qpid.client.message.AMQMessageDelegate_0_10 delegate = (org.apache.qpid.client.message.AMQMessageDelegate_0_10)(((org.apache.qpid.client.message.AbstractJMSMessage)msg).getDelegate());
+ byte[] rawUserId = delegate.getMessageProperties().getUserId();
+ if (rawUserId != null)
+ {
+ String userId = new String(rawUserId);
+ object.put("_user_id", userId);
+ }
+
+ return object;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * JMS QMF returns amqp/list types as a BytesMessage this method decodes that into a java.util.List
+ * <p>
+ * Taken from Gordon Sim's initial JMS QMF Example using the BBDecoder
+ * <p>
+ * Trivia: This block of code from Gordon Sim is the seed that spawned the whole of this Java QMF2 API
+ * implementation - cheers Gordon.
+ *
+ * @param message amqp/list encoded JMS Message
+ * @return a java.util.List decoded from Message
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<T> getList(final Message message) throws JMSException
+ {
+ if (message == null)
+ {
+ throw new MessageFormatException("Attempting to do AMQPMessage.getList() on null Message");
+ }
+ else if (message instanceof BytesMessage)
+ {
+ BytesMessage msg = (BytesMessage)message;
+
+ //only handles responses up to 2^31-1 bytes long
+ byte[] data = new byte[(int) msg.getBodyLength()];
+ msg.readBytes(data);
+ BBDecoder decoder = new BBDecoder();
+ decoder.init(ByteBuffer.wrap(data));
+ return (List<T>)decoder.readList();
+ }
+ else if (message instanceof MapMessage)
+ { /*
+ * In Qpid version 0.20 instead of exposing amqp/list as a BytesMessage as above rather it is exposed
+ * as a MapMessage!!??? the Object Keys are the indices into the List. We create a java.util.List
+ * out of this by iterating through the getMapNames() Enumeration and copying the Objects into the List.
+ * This amount of copying doesn't feel healthy and we can't even work out the capacity for the List
+ * a priori, but I'm not sure of a better way at present. I can't say I much like how amqp/list or indeed
+ * amqp/map are currently encoded. I'd *much* prefer to see them exposed as JMS ObjectMessage.
+ */
+ MapMessage msg = (MapMessage)message;
+ List resultList = new ArrayList(50); // Initial capacity of 50, can we better estimate this?
+
+ for (Enumeration e = msg.getMapNames(); e.hasMoreElements();)
+ {
+ String key = (String)e.nextElement();
+ resultList.add(msg.getObject(key));
+ }
+ return resultList;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Creates an amqp/list encoded Message out of a BytesMessage.
+ * <p>
+ * This is somewhat of a dirty hack that needs to be monitored as qpid versions change.
+ * <p>
+ * Unfortunately there's no "clean" way to encode or decode amqp/list messages via the JMS API.
+ *
+ * @param session used to create the JMS Message
+ * @return an amqp/list encoded JMS Message
+ */
+ public static Message createListMessage(final Session session) throws JMSException
+ {
+ BytesMessage message = session.createBytesMessage();
+ setContentType(message, "amqp/list");
+ return message;
+ }
+
+ /**
+ * Encodes a java.util.List on an amqp/list encoded BytesMessage.
+ * <p>
+ * This is somewhat of a dirty hack that needs to be monitored as qpid versions change.
+ * <p>
+ * This method uses the org.apache.qpid.transport.codec.BBEncoder writeList() method to encode
+ * a List into a ByteBuffer then writes the bytes from the buffer into a JMS BytesMessage.
+ *
+ * @param message amqp/list encoded JMS BytesMessage
+ * @param list to encode into JMS Message
+ */
+ @SuppressWarnings("unchecked")
+ public static void setList(final Message message, final List list) throws JMSException
+ {
+ String type = getContentType(message);
+ if (!type.equals("amqp/list"))
+ {
+ throw new MessageFormatException("Can only do setList() on amqp/list encoded Message");
+ }
+
+ if (message == null)
+ {
+ throw new MessageFormatException("Attempting to do AMQPMessage.setList() on null Message");
+ }
+ else if (message instanceof BytesMessage)
+ {
+ BBEncoder encoder = new BBEncoder(1024);
+ encoder.writeList(list);
+ ByteBuffer buf = encoder.segment();
+ byte[] data = new byte[buf.limit()];
+ buf.get(data);
+ ((BytesMessage)message).writeBytes(data);
+ }
+ else
+ {
+ throw new MessageFormatException("Attempting to do setList() on " + message.getClass().getCanonicalName());
+ }
+ }
+}
+
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BlockingNotifier.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BlockingNotifier.java
new file mode 100644
index 0000000000..634a5e60b0
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BlockingNotifier.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * Implementation of the Notifier Interface that provides a waitForWorkItem() method which blocks until the
+ * Console has called the indication() method indicating that there are WorkItems available.
+ * <p>
+ * This class isn't part of the QMF2 API however it's almost certainly how most clients would choose to use the
+ * Notifier API so it seems useful to provide an implementation.
+ *
+ * @author Fraser Adams
+ */
+public final class BlockingNotifier implements Notifier
+{
+ private boolean _waiting = true;
+
+ /**
+ * This method blocks until the indication() method has been called, this is generally called by the Console
+ * when new WorkItems are made available.
+ */
+ public synchronized void waitForWorkItem()
+ {
+ while (_waiting)
+ {
+ try
+ {
+ wait();
+ }
+ catch (InterruptedException ie)
+ {
+ continue;
+ }
+ }
+ _waiting = true;
+ }
+
+ /**
+ * Called to indicate the availability of WorkItems. This method unblocks waitForWorkItem()
+ */
+ public synchronized void indication()
+ {
+ _waiting = false;
+ notifyAll();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanEquals.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanEquals.java
new file mode 100644
index 0000000000..2ab3e5c099
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanEquals.java
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanEquals Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanEquals extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanEquals
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanEquals(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanEquals()
+ {
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanEquals(final List expr) throws QmfException
+ {
+ super(2, expr);
+ }
+
+ /**
+ * Evaluate "equal to" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ populateOperands(data);
+
+ if (_operands[0] == null || _operands[1] == null)
+ {
+ return false;
+ }
+
+ return _operands[0].equals(_operands[1]);
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExists.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExists.java
new file mode 100644
index 0000000000..a9c355c7fb
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExists.java
@@ -0,0 +1,72 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanExists Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanExists extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanExists
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanExists(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanExists()
+ {
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanExists(final List expr) throws QmfException
+ {
+ super(1, expr);
+ }
+
+ /**
+ * Evaluate "exists" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ return _operands[0] != null;
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExpression.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExpression.java
new file mode 100644
index 0000000000..999dd6d222
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanExpression.java
@@ -0,0 +1,221 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class represents the base class for all Boolean Expressions created by expanding the Query predicate.
+ *
+ * @author Fraser Adams
+ */
+public abstract class BooleanExpression extends Expression
+{
+ private static Map<String, BooleanExpression> _factories = new HashMap<String, BooleanExpression>();
+ protected String[] _operands;
+ private String[] _keys;
+
+ /**
+ * Initialise the _factories Map, which contains the prototype instances of each concrete BooleanExpression
+ * keyed by the operator String.
+ */
+ static
+ {
+ _factories.put("eq", new BooleanEquals());
+ _factories.put("ne", new BooleanNotEquals());
+ _factories.put("lt", new BooleanLessThan());
+ _factories.put("le", new BooleanLessEqual());
+ _factories.put("gt", new BooleanGreaterThan());
+ _factories.put("ge", new BooleanGreaterEqual());
+ _factories.put("re_match", new BooleanRegexMatch());
+ _factories.put("exists", new BooleanExists());
+ _factories.put("true", new BooleanTrue());
+ _factories.put("false", new BooleanFalse());
+ }
+
+ /**
+ * Factory method to create concrete Expression instances based on the operator name extracted from the expression List.
+ * This method will create a BooleanExpression from an "eq", "ne", "lt" etc. operator using the prototype
+ * obtained from the _factories Map.
+ *
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public static Expression createExpression(final List expr) throws QmfException
+ {
+ Iterator iter = expr.listIterator();
+ if (!iter.hasNext())
+ {
+ throw new QmfException("Missing operator in predicate expression");
+ }
+
+ String op = (String)iter.next();
+ BooleanExpression factory = _factories.get(op);
+ if (factory == null)
+ {
+ throw new QmfException("Unknown operator in predicate expression");
+ }
+
+ return factory.create(expr);
+ }
+
+ /**
+ * Factory method to create a concrete instance of BooleanExpression
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public abstract Expression create(final List expr) throws QmfException;
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ protected BooleanExpression()
+ {
+ }
+
+ /**
+ * Main Constructor, used to populate unevaluated operands. This loops through the input expression list. If the
+ * Object is a String is is treated as a key such that when the expression is evaluated the key will be used to
+ * obtain a propery from the QmfData object. If the Object is a sub-List it is checked to see if it's a quoted
+ * String, if it is the quoted String is stored as the operand. If it's neither of these the actual object from
+ * the expression List is used as the operand.
+ *
+ * @param operandCount the number of operands in this Expression, the value is generally passed by the subclass.
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ protected BooleanExpression(final int operandCount, final List expr) throws QmfException
+ {
+ Iterator iter = expr.listIterator();
+ String op = (String)iter.next(); // We've already tested for hasNext() in the factory
+
+ _operands = new String[operandCount];
+ _keys = new String[operandCount];
+
+ for (int i = 0; i < operandCount; i++)
+ {
+ if (!iter.hasNext())
+ {
+ throw new QmfException("Too few operands for operation: " + op);
+ }
+
+ Object object = iter.next();
+ _operands[i] = object.toString();
+
+ if (object instanceof String)
+ {
+ _keys[i] = _operands[i];
+ _operands[i] = null;
+ }
+ else if (object instanceof List)
+ {
+ List sublist = (List)object;
+ Iterator subiter = sublist.listIterator();
+
+ if (subiter.hasNext() && ((String)subiter.next()).equals("quote"))
+ {
+ if (subiter.hasNext())
+ {
+ _operands[i] = subiter.next().toString();
+ if (subiter.hasNext())
+ {
+ throw new QmfException("Extra tokens at end of 'quote'");
+ }
+ }
+ }
+ else
+ {
+ throw new QmfException("Expected '[quote, <token>]'");
+ }
+ }
+ }
+
+ if (iter.hasNext())
+ {
+ throw new QmfException("Too many operands for operation: " + op);
+ }
+ }
+
+ /**
+ * Populates operands that are obtained at evaluation time. In other words operands that are obtained by using
+ * the key obtained from the static operand evaluation to look up an associated property from the QmfData object.
+ * @param data the object to extract the operand(s) from
+ */
+ protected void populateOperands(final QmfData data)
+ {
+ for (int i = 0; i < _operands.length; i++)
+ {
+ String key = _keys[i];
+ if (key != null)
+ {
+ String value = null;
+
+ if (data.hasValue(key))
+ { // If there's a property of the data object named key look it up as a String
+ value = data.getStringValue(key);
+ }
+ else
+ { // If there's no property of the data object named key look up its Described/Managed metadata
+ if (data instanceof QmfManaged)
+ {
+ QmfManaged managedData = (QmfManaged)data;
+ if (key.equals("_schema_id"))
+ {
+ value = managedData.getSchemaClassId().toString();
+ }
+ else if (key.equals("_object_id"))
+ {
+ value = managedData.getObjectId().toString();
+ }
+ else if (managedData.getSchemaClassId().hasValue(key))
+ { // If it's not _schema_id or _object_id check the SchemaClassId properties e.g.
+ // _package_name, _class_name, _type or _hash
+ value = managedData.getSchemaClassId().getStringValue(key);
+ }
+ }
+
+ if (value == null)
+ { // If a value still can't be found for the key check if it's available in the mapEncoded form
+ Map m = data.mapEncode();
+ if (m.containsKey(key))
+ {
+ value = QmfData.getString(m.get(key));
+ }
+ }
+ }
+
+ _operands[i] = value;
+ }
+//System.out.println("key: " + key + ", operand = " + _operands[i]);
+ }
+ }
+
+ /**
+ * Evaluate expression against a QmfData instance.
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public abstract boolean evaluate(final QmfData data);
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanFalse.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanFalse.java
new file mode 100644
index 0000000000..00080dfb10
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanFalse.java
@@ -0,0 +1,60 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanFalse Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanFalse extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanFalse
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanFalse();
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanFalse()
+ {
+ }
+
+ /**
+ * Evaluate "false" expression against a QmfData instance.
+ * @param data the object to evaluate the expression against
+ * @return false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ return false;
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterEqual.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterEqual.java
new file mode 100644
index 0000000000..c9593ffa33
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterEqual.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanGreaterEqual Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanGreaterEqual extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanGreaterEqual
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanGreaterEqual(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanGreaterEqual()
+ {
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanGreaterEqual(final List expr) throws QmfException
+ {
+ super(2, expr);
+ }
+
+ /**
+ * Evaluate "greater than or equal to" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ populateOperands(data);
+
+ if (_operands[0] == null || _operands[1] == null)
+ {
+ return false;
+ }
+
+ try
+ {
+ double l = Double.parseDouble(_operands[0]);
+ double r = Double.parseDouble(_operands[1]);
+ return l >= r;
+ }
+ catch (NumberFormatException nfe)
+ {
+ // If converting to double fails try a lexicographic comparison
+ return _operands[0].compareTo(_operands[1]) >= 0;
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterThan.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterThan.java
new file mode 100644
index 0000000000..65b7d82735
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanGreaterThan.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanGreaterThan Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanGreaterThan extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanGreaterThan
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanGreaterThan(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanGreaterThan()
+ {
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanGreaterThan(final List expr) throws QmfException
+ {
+ super(2, expr);
+ }
+
+ /**
+ * Evaluate "greater than" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(QmfData data)
+ {
+ populateOperands(data);
+
+ if (_operands[0] == null || _operands[1] == null)
+ {
+ return false;
+ }
+
+ try
+ {
+ double l = Double.parseDouble(_operands[0]);
+ double r = Double.parseDouble(_operands[1]);
+ return l > r;
+ }
+ catch (NumberFormatException nfe)
+ {
+ // If converting to double fails try a lexicographic comparison
+ return _operands[0].compareTo(_operands[1]) > 0;
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessEqual.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessEqual.java
new file mode 100644
index 0000000000..729495ffc2
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessEqual.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanLessEqual Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanLessEqual extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanLessEqual
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanLessEqual(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanLessEqual()
+ {
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanLessEqual(final List expr) throws QmfException
+ {
+ super(2, expr);
+ }
+
+ /**
+ * Evaluate "less than or equal to" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ populateOperands(data);
+
+ if (_operands[0] == null || _operands[1] == null)
+ {
+ return false;
+ }
+
+ try
+ {
+ double l = Double.parseDouble(_operands[0]);
+ double r = Double.parseDouble(_operands[1]);
+ return l <= r;
+ }
+ catch (NumberFormatException nfe)
+ {
+ // If converting to double fails try a lexicographic comparison
+ return _operands[0].compareTo(_operands[1]) <= 0;
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessThan.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessThan.java
new file mode 100644
index 0000000000..540a292c4e
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanLessThan.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanLessThan Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanLessThan extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanLessThan
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanLessThan(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanLessThan()
+ {
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanLessThan(final List expr) throws QmfException
+ {
+ super(2, expr);
+ }
+
+ /**
+ * Evaluate "less than" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ populateOperands(data);
+
+ if (_operands[0] == null || _operands[1] == null)
+ {
+ return false;
+ }
+
+ try
+ {
+ double l = Double.parseDouble(_operands[0]);
+ double r = Double.parseDouble(_operands[1]);
+ return l < r;
+ }
+ catch (NumberFormatException nfe)
+ {
+ // If converting to double fails try a lexicographic comparison
+ return _operands[0].compareTo(_operands[1]) < 0;
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanNotEquals.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanNotEquals.java
new file mode 100644
index 0000000000..50c5863e61
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanNotEquals.java
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanNotEquals Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanNotEquals extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanNotEquals
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanNotEquals(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanNotEquals()
+ {
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanNotEquals(final List expr) throws QmfException
+ {
+ super(2, expr);
+ }
+
+ /**
+ * Evaluate "not equal to" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ populateOperands(data);
+
+ if (_operands[0] == null || _operands[1] == null)
+ {
+ return false;
+ }
+
+ return !_operands[0].equals(_operands[1]);
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanRegexMatch.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanRegexMatch.java
new file mode 100644
index 0000000000..9fe3f9733a
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanRegexMatch.java
@@ -0,0 +1,95 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * A class to create and evaluate the BooleanRegexMatch Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanRegexMatch extends BooleanExpression
+{
+ private final Pattern _pattern;
+
+ /**
+ * Factory method to create an instance of BooleanRegexMatch
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanRegexMatch(expr);
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanRegexMatch()
+ {
+ _pattern = null;
+ }
+
+ /**
+ * Main Constructor, uses base class constructor to populate unevaluated operands
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public BooleanRegexMatch(final List expr) throws QmfException
+ {
+ super(2, expr);
+
+ try
+ {
+ _pattern = Pattern.compile(_operands[1]);
+ }
+ catch (PatternSyntaxException pse)
+ {
+ throw new QmfException("Error in regular expression " + pse.getMessage());
+ }
+ }
+
+ /**
+ * Evaluate "regex match" expression against a QmfData instance.
+ * N.B. to avoid complexities with types this class treats operands as Strings performing an appropriate evaluation
+ * of the String that makes sense for a given expression e.g. parsing as a double for >, >=, <, <=
+ *
+ * @param data the object to evaluate the expression against
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ populateOperands(data);
+
+ if (_operands[0] == null || _operands[1] == null || _pattern == null)
+ {
+ return false;
+ }
+
+ Matcher matcher = _pattern.matcher(_operands[0]);
+ return matcher.find();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanTrue.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanTrue.java
new file mode 100644
index 0000000000..b092e7daaf
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/BooleanTrue.java
@@ -0,0 +1,60 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to create and evaluate the BooleanTrue Expression
+ *
+ * @author Fraser Adams
+ */
+public final class BooleanTrue extends BooleanExpression
+{
+ /**
+ * Factory method to create an instance of BooleanTrue
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ * @return an instance of the concrete BooleanExpression
+ */
+ public Expression create(final List expr) throws QmfException
+ {
+ return new BooleanTrue();
+ }
+
+ /**
+ * Basic Constructor primarily used by the prototype instance of each concrete BooleanExpression
+ */
+ public BooleanTrue()
+ {
+ }
+
+ /**
+ * Evaluate "true" expression against a QmfData instance.
+ * @param data the object to evaluate the expression against
+ * @return true.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ return true;
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Expression.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Expression.java
new file mode 100644
index 0000000000..1d82b7857b
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Expression.java
@@ -0,0 +1,77 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This class represents the base class for all Expressions created by expanding the Query predicate.
+ * <p>
+ * Depending on the structure of the expression list there might be a nested structure of Expressions comprising
+ * a mixture of LogicalExpressions and BooleanExpressions.
+ * <p>
+ * The Expression structure is illustrated below in the context of its relationship with QmfQuery.
+ * <img src="doc-files/QmfQuery.png"/>
+ *
+ * @author Fraser Adams
+ */
+public abstract class Expression
+{
+ /**
+ * Factory method to create concrete Expression instances base on the operator name extracted from the expression List.
+ * This method will create a LogicalExpression from an "and", "or" or "not" operator otherwise it will create
+ * a BooleanExpression.
+ *
+ * @param expr the List of Expressions extracted by parsing the Query predicate
+ */
+ public static Expression createExpression(final List expr) throws QmfException
+ {
+ Iterator iter = expr.listIterator();
+ if (!iter.hasNext())
+ {
+ throw new QmfException("Missing operator in predicate expression");
+ }
+
+ String op = (String)iter.next();
+ if (op.equals("not"))
+ {
+ return new LogicalNot(expr);
+ }
+ if (op.equals("and"))
+ {
+ return new LogicalAnd(expr);
+ }
+ if (op.equals("or"))
+ {
+ return new LogicalOr(expr);
+ }
+ return BooleanExpression.createExpression(expr);
+ }
+
+ /**
+ * Evaluate expression against a QmfData instance.
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public abstract boolean evaluate(final QmfData data);
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Handle.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Handle.java
new file mode 100644
index 0000000000..7f81b06900
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Handle.java
@@ -0,0 +1,107 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// JMS Imports
+import javax.jms.Destination; // Needed for replyTo
+import javax.jms.JMSException;
+
+/**
+ * This class represents the reply Handle used for asynchronous operations
+ *
+ * @author Fraser Adams
+ */
+public final class Handle
+{
+ private final String _correlationId;
+ private final Destination _replyTo;
+
+ /**
+ * Construct a Handle containing only a correlationId
+ *
+ * @param correlationId - a String used to tie together requests and responses
+ */
+ public Handle(final String correlationId)
+ {
+ _correlationId = correlationId;
+ _replyTo = null;
+ }
+
+ /**
+ * Construct a Handle containing a correlationId and a replyTo.
+ *
+ * @param correlationId - a String used to tie together requests and responses
+ * @param replyTo - the JMS replyTo
+ */
+ public Handle(final String correlationId, final Destination replyTo)
+ {
+ _correlationId = correlationId;
+ _replyTo = replyTo;
+ }
+
+ /**
+ * Returns the correlationId String.
+ * @return the correlationId String
+ */
+ public String getCorrelationId()
+ {
+ return _correlationId;
+ }
+
+ /**
+ * Return the replyTo Destination.
+ * @return the replyTo Destination
+ */
+ public Destination getReplyTo()
+ {
+ return _replyTo;
+ }
+
+ /**
+ * Returns the Routing Key for the replyTo as a String
+ * <p>
+ * All things being equal it probably makes most logical sense to use the replyTo obtained from the JMS
+ * Message when replying to a request however..... for Qpid up to version 0.12 at least there seems to be
+ * a bug with the replyTo whereby invoking send() on the replyTo causes spurious exchangeDeclares to occur.
+ * The exchangeDeclare is apparently to validate the destination however there is supposed to be a cache
+ * that should prevent this from occurring if the replyTo Destination is reused, but that's broken.
+ * <p>
+ * As an alternative we get hold of the Routing Key of the replyTo which, is sneakily available from getTopicName()
+ * the Routing Key can then be used as the subject of the returned message to enable delivery of the Message
+ * to the appropriate address.
+ * <p>
+ * org.apache.qpid.client.AMQTopic.getTopicName() returns "getRoutingKey().asString()" so this seems an OK
+ * way to get the Routing Key from the replyTo using the pure JMS API.
+ *
+ * @return the Routing Key for the replyTo
+ */
+ public String getRoutingKey()
+ {
+ try
+ {
+ return ((javax.jms.Topic)_replyTo).getTopicName();
+ }
+ catch (JMSException jmse)
+ {
+ return "";
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalAnd.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalAnd.java
new file mode 100644
index 0000000000..12b9f3d093
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalAnd.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to evaluate the LogicalAnd Expression
+ *
+ * @author Fraser Adams
+ */
+
+public final class LogicalAnd extends LogicalExpression
+{
+ /**
+ * This method iterates through collecting the sub-expressions of the Logical Expression
+ *
+ * @param expr the List of sub-expressions extracted by parsing the Query predicate, the first one should be
+ * the Logical Expression's operator name
+ */
+ public LogicalAnd(final List expr) throws QmfException
+ {
+ super(expr);
+ }
+
+ /**
+ * Evaluate the Logical And expression against a QmfData instance.
+ * @return false if any of the sub-expressions is false otherwise returns true
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ for (Expression e : _subExpressions)
+ {
+ if (!e.evaluate(data))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalExpression.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalExpression.java
new file mode 100644
index 0000000000..23a5ac3abd
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalExpression.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/*
+ * This class represents the base class for all Logical Expressions (and, or, not) created by expanding the Query predicate.
+ *
+ * @author Fraser Adams
+ */
+public abstract class LogicalExpression extends Expression
+{
+ protected List<Expression> _subExpressions = new ArrayList<Expression>();
+
+ /**
+ * Constructor. This method iterates through collecting the sub-expressions of the Logical Expression
+ *
+ * @param expr the List of sub-expressions extracted by parsing the Query predicate, the first one should be
+ * the Logical Expression's operator name
+ */
+ public LogicalExpression(final List expr) throws QmfException
+ {
+ Iterator iter = expr.listIterator();
+ String op = (String)iter.next();
+//System.out.println("LogicalExpression, op = " + op);
+
+ // Collect sub-expressions
+ while (iter.hasNext())
+ {
+ Object object = iter.next();
+ if (object instanceof List)
+ {
+ _subExpressions.add(createExpression((List)object));
+ }
+ else
+ {
+ throw new QmfException("Operands of " + op + " must be Lists");
+ }
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalNot.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalNot.java
new file mode 100644
index 0000000000..029ea00af9
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalNot.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to evaluate the LogicalNot Expression
+ *
+ * @author Fraser Adams
+ */
+
+public final class LogicalNot extends LogicalExpression
+{
+ /**
+ * This method iterates through collecting the sub-expressions of the Logical Expression
+ *
+ * @param expr the List of sub-expressions extracted by parsing the Query predicate, the first one should be
+ * the Logical Expression's operator name
+ */
+ public LogicalNot(final List expr) throws QmfException
+ {
+ super(expr);
+ }
+
+ /**
+ * Evaluate the Logical Not expression against a QmfData instance.
+ * @return false if any of the sub-expressions is true otherwise returns true
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ for (Expression e : _subExpressions)
+ {
+ if (e.evaluate(data))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalOr.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalOr.java
new file mode 100644
index 0000000000..72c8c1ff15
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/LogicalOr.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.List;
+
+/**
+ * A class to evaluate the LogicalOr Expression
+ *
+ * @author Fraser Adams
+ */
+
+public final class LogicalOr extends LogicalExpression
+{
+ /**
+ * This method iterates through collecting the sub-expressions of the Logical Expression
+ *
+ * @param expr the List of sub-expressions extracted by parsing the Query predicate, the first one should be
+ * the Logical Expression's operator name
+ */
+ public LogicalOr(final List expr) throws QmfException
+ {
+ super(expr);
+ }
+
+ /**
+ * Evaluate the Logical Or expression against a QmfData instance.
+ * @return true if any of the sub-expressions is true otherwise returns false
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ for (Expression e : _subExpressions)
+ {
+ if (e.evaluate(data))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Notifier.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Notifier.java
new file mode 100644
index 0000000000..61b048832f
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/Notifier.java
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * The QMF2 API has a work-queue Callback approach. All asynchronous events are represented by a WorkItem object.
+ * When a QMF event occurs it is translated into a WorkItem object and placed in a FIFO queue. It is left to the
+ * application to drain this queue as needed.
+ * <p>
+ * This new API does require the application to provide a single callback. The callback is used to notify the
+ * application that WorkItem object(s) are pending on the work queue. This callback is invoked by QMF when one or
+ * more new WorkItem objects are added to the queue. To avoid any potential threading issues, the application is
+ * not allowed to call any QMF API from within the context of the callback. The purpose of the callback is to
+ * notify the application to schedule itself to drain the work queue at the next available opportunity.
+ * <p>
+ * For example, a console application may be designed using a select() loop. The application waits in the select()
+ * for any of a number of different descriptors to become ready. In this case, the callback could be written to
+ * simply make one of the descriptors ready, and then return. This would cause the application to exit the wait state,
+ * and start processing pending events.
+ * <p>
+ * The callback is represented by the Notifier virtual base class. This base class contains a single method. An
+ * application derives a custom notification handler from this class, and makes it available to the Console or Agent object.
+ * <p>
+ * The following diagram illustrates the Notifier and WorkQueue QMF2 API Event model.
+ * <p>
+ * Notes
+ * <ol>
+ * <li>There is an alternative (simpler but not officially QMF2) API based on implementing the QmfEventListener.</li>
+ * <li>BlockingNotifier is not part of QMF2 either but is how most people would probably write a Notifier.</li>
+ * <li>It's generally not necessary to use a Notifier as the Console provides a blocking getNextWorkitem() method.</li>
+ * </ol>
+ * <p>
+ * <img src="doc-files/WorkQueueEventModel.png"/>
+ *
+ * @author Fraser Adams
+ */
+public interface Notifier extends QmfCallback
+{
+ /**
+ * Called when the Console internal work queue becomes non-empty due to the arrival of one or more WorkItems.
+ * <p>
+ * This method will be called by the internal QMF management thread. It is illegal to invoke any QMF APIs
+ * from within this callback. The purpose of this callback is to indicate that the application should schedule
+ * itself to process the work items. A common implementation would be to call notify() to unblock a waiting Thread.
+ *
+ */
+ public void indication();
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NotifierWrapper.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NotifierWrapper.java
new file mode 100644
index 0000000000..42bb9cc9d7
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NotifierWrapper.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * Implementation of QmfEventListener that wraps a Notifier instance. This class populates the WorkItem
+ * queue then invokes the Notifier's indication() method to notify clients of available data.
+ * <p>
+ * This approach allows us to support two separate asynchronous notification APIs without too much effort.
+ *
+ * @author Fraser Adams
+ */
+public final class NotifierWrapper implements QmfEventListener
+{
+ private final Notifier _notifier;
+ private final WorkQueue _workQueue;
+
+ /**
+ * Wraps a Notifier and WorkQueue so that they me be triggered by a QmfEventListener onEvent() call.
+ * @param notifier the Notifier instance that will be triggered when NotifierWrapper receives a WorkItem.
+ * @param workQueue the WorkQueue instance that the WorkItem will be placed on.
+ */
+ public NotifierWrapper(final Notifier notifier, final WorkQueue workQueue)
+ {
+ _notifier = notifier;
+ _workQueue = workQueue;
+ }
+
+ /**
+ * This method adds the WorkItem to the WorkQueue then notifies any clients through the Notifier.indication().
+ *
+ * @param item the WorkItem to add to the queue
+ */
+ public void onEvent(final WorkItem item)
+ {
+ _workQueue.addWorkItem(item);
+ _notifier.indication();
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NullQmfEventListener.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NullQmfEventListener.java
new file mode 100644
index 0000000000..447adbe391
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/NullQmfEventListener.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * Implementation of QmfEventListener with an empty onEvent().
+ * <p>
+ * Agent or Console instantiate this class if no QmfCallback is supplied so they can avoid lots of ugly tests for
+ * _eventListener == null.
+ *
+ * @author Fraser Adams
+ */
+public final class NullQmfEventListener implements QmfEventListener
+{
+ /**
+ * Passes a WorkItem to the listener. This class provides a null implementation
+ *
+ * @param item the WorkItem passed to the listener
+ */
+ public void onEvent(final WorkItem item)
+ {
+ // Null implementation
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/ObjectId.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/ObjectId.java
new file mode 100644
index 0000000000..b84822def7
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/ObjectId.java
@@ -0,0 +1,159 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Map;
+
+/**
+ * This class provides a wrapper for QMF Object IDs to enable easier comparisons.
+ * <p>
+ * QMF Object IDs are Maps and <i>in theory</i> equals should work, but strings in QMF are actually often returned
+ * as byte[] due to inconsistent binary and UTF-8 encodings being used and byte[].equals() compares the address not a
+ * bytewise comparison.
+ * <p>
+ * This class creates a String from the internal ObjectId state information to enable easier comparison and rendering.
+ *
+ * @author Fraser Adams
+ */
+public final class ObjectId extends QmfData
+{
+ private final String _agentName;
+ private final String _objectName;
+ private final long _agentEpoch;
+
+ /**
+ * Create an ObjectId given the ID created via ObjectId.toString().
+ * @param oid a string created via ObjectId.toString().
+ */
+ public ObjectId(String oid)
+ {
+ String[] split = oid.split("@");
+
+ _agentName = split.length == 3 ? split[0] : "";
+ _agentEpoch = split.length == 3 ? Long.parseLong(split[1]) : 0;
+ _objectName = split.length == 3 ? split[2] : "";
+
+ setValue("_agent_name", _agentName);
+ setValue("_agent_epoch", _agentEpoch);
+ setValue("_object_name", _objectName);
+ }
+
+ /**
+ * Create an ObjectId given an agentName, objectName and agentEpoch.
+ * @param agentName the name of the Agent managing the object.
+ * @param objectName the name of the managed object.
+ * @param agentEpoch a count used to identify if an Agent has been restarted.
+ */
+ public ObjectId(String agentName, String objectName, long agentEpoch)
+ {
+ _agentName = agentName;
+ _objectName = objectName;
+ _agentEpoch = agentEpoch;
+ setValue("_agent_name", _agentName);
+ setValue("_object_name", _objectName);
+ setValue("_agent_epoch", _agentEpoch);
+ }
+
+ /**
+ * Create an ObjectId from a Map. In essence it "deserialises" its state from the Map.
+ * @param m the Map the Object is retrieving its state from.
+ */
+ public ObjectId(Map m)
+ {
+ super(m);
+ _agentName = getStringValue("_agent_name");
+ _objectName = getStringValue("_object_name");
+ _agentEpoch = getLongValue("_agent_epoch");
+ }
+
+ /**
+ * Create an ObjectId from a QmfData object. In essence it "deserialises" its state from the QmfData object.
+ * @param qmfd the QmfData the Object is retrieving its state from.
+ */
+ public ObjectId(QmfData qmfd)
+ {
+ this(qmfd.mapEncode());
+ }
+
+ /**
+ * Returns the name of the Agent managing the object.
+ * @return the name of the Agent managing the object.
+ */
+ public String getAgentName()
+ {
+ return _agentName;
+ }
+
+ /**
+ * Returns the name of the managed object.
+ * @return the name of the managed object.
+ */
+ public String getObjectName()
+ {
+ return _objectName;
+ }
+
+ /**
+ * Returns the Epoch count.
+ * @return the Epoch count.
+ */
+ public long getAgentEpoch()
+ {
+ return _agentEpoch;
+ }
+
+ /**
+ * Compares two ObjectId objects for equality.
+ * @param rhs the right hands side ObjectId in the comparison.
+ * @return true if the two ObjectId objects are equal otherwise returns false.
+ */
+ @Override
+ public boolean equals(Object rhs)
+ {
+ if (rhs instanceof ObjectId)
+ {
+ return toString().equals(rhs.toString());
+ }
+ return false;
+ }
+
+ /**
+ * Returns the ObjectId hashCode.
+ * @return the ObjectId hashCode.
+ */
+ @Override
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ /**
+ * Returns a String representation of the ObjectId.
+ * @return a String representation of the ObjectId.
+ */
+ @Override
+ public String toString()
+ {
+ return _agentName + "@" + _agentEpoch + "@" + _objectName;
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfCallback.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfCallback.java
new file mode 100644
index 0000000000..d57282b2e7
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfCallback.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * QmfCallback is a "marker interface" used to specify objects that will be notified of a particular
+ * condition by the Console. This interface is extended by the QmfEventListener and Notifier interfaces
+ * in order to provide two different types of callback semantic.
+ *
+ * @author Fraser Adams
+ */
+public interface QmfCallback
+{
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java
new file mode 100644
index 0000000000..571db16064
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfData.java
@@ -0,0 +1,443 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * QMF defines the QmfData class to represent an atomic unit of managment data.
+ * <p>
+ * The QmfData class defines a collection of named data values. Optionally, a string tag, or "sub-type" may be
+ * associated with each data item. This tag may be used by an application to annotate the data item.
+ * (Note the tag implementation is TBD).
+ * <p>
+ * In QMFv2, message bodies are AMQP maps and are therefore easily extended without causing backward
+ * compatibility problems. Another benefit of the map-message format is that all messages can be fully
+ * parsed when received without the need for external schema data
+ * <p>
+ * This class is the base class for all QMF2 Data Types in this implementation. It is intended to provide a
+ * useful wrapper for the underlying Map, supplying accessor and mutator methods that give an element of type
+ * safety (for example strings appear to be encoded as a mixture of byte[] and String depending of the agent, so
+ * this class checks for this in its getString())
+ * <p>
+ * The following diagram represents the QmfData class hierarchy.
+ * <p>
+ * <img src="doc-files/QmfData.png"/>
+ *
+ * @author Fraser Adams
+ */
+public class QmfData
+{
+ protected Map<String, Object> _values = null;
+ protected Map<String, String> _subtypes = null;
+
+ /**
+ * The default constructor, initialises the QmfData with an empty Map.
+ */
+ public QmfData()
+ {
+ _values = new HashMap<String, Object>();
+ }
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+ *
+ * @param m the Map used to construct the QmfData.
+ */
+ @SuppressWarnings("unchecked")
+ public QmfData(final Map m)
+ {
+ if (m == null)
+ { // This branch is just a safety precaution and shouldn't generally occur in normal usage scenarios.
+ // Initialise with a new HashMap. Should then behave the same as the default Constructor.
+ _values = new HashMap<String, Object>();
+ }
+ else
+ {
+ Map<String, Object> values = (Map<String, Object>)m.get("_values");
+ _values = (values == null) ? m : values;
+
+ Map<String, String> subtypes = (Map<String, String>)m.get("_subtypes");
+ _subtypes = subtypes;
+ }
+ }
+
+ /**
+ * Get the state of the _subtypes Map, (generally used when serialising method request/response arguments.
+ *
+ * @return the value of the _subtypes Map.
+ */
+ public Map<String, String> getSubtypes()
+ {
+ return _subtypes;
+ }
+
+
+ /**
+ * Set the state of the _subtypes Map, (generally used when deserialising method request/response arguments.
+ *
+ * @param subtypes the new value of the _subtypes Map.
+ */
+ @SuppressWarnings("unchecked")
+ public void setSubtypes(Map subtypes)
+ {
+ _subtypes = subtypes;
+ }
+
+ /**
+ * Helper method to return the <i>best</i> String representation of the given Object.
+ * <p>
+ * There seem to be some inconsistencies where string properties are sometimes returned as byte[] and
+ * sometimes as Strings. It seems to vary depending on the Agent and is due to strings being encoded as a mix of
+ * binary strings and UTF-8 strings by C++ Agent classes. Getting it wrong results in ClassCastExceptions, which
+ * is clearly unfortunate.
+ * <p>
+ * This is basically a helper method to check the type of a property and return the most "appropriate"
+ * String representation for it.
+ *
+ * @param p a property in Object form
+ * @return the most appropriate String representation of the property
+ */
+ public static final String getString(final Object p)
+ {
+ if (p == null)
+ {
+ return "";
+ }
+ else if (p instanceof String)
+ {
+ return (String)p;
+ }
+ else if (p instanceof byte[])
+ {
+ return new String((byte[])p);
+ }
+ else return p.toString();
+ }
+
+ /**
+ * Helper method to return the <i>best</i> long representation of the given Object.
+ * <p>
+ * There seem to be some inconsistencies where properties are sometimes returned as Integer and
+ * sometimes as Long. It seems to vary depending on the Agent and getting it wrong results in
+ * ClassCastExceptions, which is clearly unfortunate.
+ * <p>
+ * This is basically a helper method to check the type of a property and return a long representation for it.
+ *
+ * @param p a property in Object form
+ * @return the long representation for it.
+ */
+ public static final long getLong(final Object p)
+ {
+ if (p == null)
+ {
+ return 0;
+ }
+ else if (p instanceof Long)
+ {
+ return ((Long)p).longValue();
+ }
+ else if (p instanceof Integer)
+ {
+ return ((Integer)p).intValue();
+ }
+ else if (p instanceof Short)
+ {
+ return ((Short)p).shortValue();
+ }
+ else return 0;
+ }
+
+ /**
+ * Helper method to return the <i>best</i> boolean representation of the given Object.
+ * <p>
+ * There seem to be some inconsistencies where boolean properties are sometimes returned as Boolean and
+ * sometimes as Long/Integer/Short. It seems to vary depending on the Agent and getting it wrong results in
+ * ClassCastExceptions, which is clearly unfortunate.
+ * <p>
+ * This is basically a helper method to check the type of a property and return a boolean representation for it.
+ *
+ * @param p a property in Object form
+ * @return the boolean representation for it.
+ */
+ public static final boolean getBoolean(final Object p)
+ {
+ if (p == null)
+ {
+ return false;
+ }
+ else if (p instanceof Boolean)
+ {
+ return ((Boolean)p).booleanValue();
+ }
+ else if (p instanceof Long)
+ {
+ return ((Long)p).longValue() > 0;
+ }
+ else if (p instanceof Integer)
+ {
+ return ((Integer)p).intValue() > 0;
+ }
+ else if (p instanceof Short)
+ {
+ return ((Short)p).shortValue() > 0;
+ }
+ else if (p instanceof String)
+ {
+ return Boolean.parseBoolean((String)p);
+ }
+ else return false;
+ }
+
+ /**
+ * Helper method to return the <i>best</i> double representation of the given Object.
+ * <p>
+ * There seem to be some inconsistencies where properties are sometimes returned as Float and
+ * sometimes as Double. It seems to vary depending on the Agent and getting it wrong results in
+ * ClassCastExceptions, which is clearly unfortunate.
+ * <p>
+ * This is basically a helper method to check the type of a property and return a Double representation for it.
+ *
+ * @param p a property in Object form
+ * @return the Double representation for it.
+ */
+ public static final double getDouble(final Object p)
+ {
+ if (p == null)
+ {
+ return 0.0d;
+ }
+ else if (p instanceof Float)
+ {
+ return ((Float)p).floatValue();
+ }
+ else if (p instanceof Double)
+ {
+ return ((Double)p).doubleValue();
+ }
+ else return 0.0d;
+ }
+
+ /**
+ * Determines if the named property exists.
+ *
+ * @param name of the property to check.
+ * @return true if the property exists otherwise false.
+ */
+ public final boolean hasValue(final String name)
+ {
+ return _values.containsKey(name);
+ }
+
+ /**
+ * Accessor method to return a named property as an Object.
+ *
+ * @param name of the property to return as an Object.
+ * @return value of property as an Object.
+ */
+ @SuppressWarnings("unchecked")
+ public final <T> T getValue(final String name)
+ {
+ return (T)_values.get(name);
+ }
+
+ /**
+ * Mutator method to set a named Object property.
+ *
+ * @param name the name of the property to set.
+ * @param value the value of the property to set.
+ */
+ public final void setValue(final String name, final Object value)
+ {
+ _values.put(name, value);
+ }
+
+ /**
+ * Mutator method to set a named Object property.
+ *
+ * @param name the name of the property to set.
+ * @param value the value of the property to set.
+ * @param subtype the subtype of the property.
+ */
+ public final void setValue(final String name, final Object value, final String subtype)
+ {
+ setValue(name, value);
+ setSubtype(name, subtype);
+ }
+
+ /**
+ * Mutator to set or modify the subtype associated with name.
+ *
+ * @param name the name of the property to set the subtype for.
+ * @param subtype the subtype of the property.
+ */
+ public final void setSubtype(final String name, final String subtype)
+ {
+ if (_subtypes == null)
+ {
+ _subtypes = new HashMap<String, String>();
+ }
+ _subtypes.put(name, subtype);
+ }
+
+ /**
+ * Accessor to return the subtype associated with named property.
+ *
+ * @param name the name of the property to get the subtype for.
+ * @return the subtype of the named property or null if not present.
+ */
+ public final String getSubtype(final String name)
+ {
+ if (_subtypes == null)
+ {
+ return null;
+ }
+ return _subtypes.get(name);
+ }
+
+ /**
+ * Accessor method to return a named property as a boolean.
+ *
+ * @param name of the property to return as a boolean.
+ * @return value of property as a boolean.
+ */
+ public final boolean getBooleanValue(final String name)
+ {
+ return getBoolean(getValue(name));
+ }
+
+ /**
+ * Accessor method to return a named property as a long.
+ *
+ * @param name of the property to return as a long.
+ * @return value of property as a long.
+ */
+ public final long getLongValue(final String name)
+ {
+ return getLong(getValue(name));
+ }
+
+ /**
+ * Accessor method to return a named property as a double.
+ *
+ * @param name of the property to return as a double.
+ * @return value of property as a double.
+ */
+ public final double getDoubleValue(final String name)
+ {
+ return getDouble(getValue(name));
+ }
+
+ /**
+ * Accessor method to return a named property as a String.
+ *
+ * @param name of the property to return as a String.
+ * @return value of property as a String.
+ */
+ public final String getStringValue(final String name)
+ {
+ return getString(getValue(name));
+ }
+
+ /**
+ * Accessor method to return a reference property.
+ * <p>
+ * Many QMF Objects contain reference properties, e.g. references to other QMF Objects.
+ * This method allows these to be obtained as ObjectId objects to enable much easier
+ * comparison and rendering.
+ * @return the retrieved value as an ObjectId instance.
+ */
+ public final ObjectId getRefValue(final String name)
+ {
+ return new ObjectId((Map)getValue(name));
+ }
+
+ /**
+ * Mutator method to set a named reference property.
+ * <p>
+ * Many QMF Objects contain reference properties, e.g. references to other QMF Objects.
+ * This method allows these to be set as ObjectId objects.
+ *
+ * @param name the name of the property to set.
+ * @param value the value of the property to set.
+ */
+ public final void setRefValue(final String name, final ObjectId value)
+ {
+ setValue(name, value.mapEncode());
+ }
+
+ /**
+ * Mutator method to set a named reference property.
+ * <p>
+ * Many QMF Objects contain reference properties, e.g. references to other QMF Objects.
+ * This method allows these to be set as ObjectId objects.
+ *
+ * @param name the name of the property to set.
+ * @param value the value of the property to set.
+ * @param subtype the subtype of the property.
+ */
+ public final void setRefValue(final String name, final ObjectId value, final String subtype)
+ {
+ setRefValue(name, value);
+ setSubtype(name, subtype);
+ }
+
+ /**
+ * Return the underlying Map representation of this QmfData.
+ * @return the underlying Map.
+ */
+ public Map<String, Object> mapEncode()
+ {
+ return _values;
+ }
+
+ /**
+ * Helper/debug method to list the properties and their type.
+ */
+ public void listValues()
+ {
+ for (Map.Entry<String, Object> entry : _values.entrySet())
+ {
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+ if (value instanceof Map)
+ { // Check if the value part is an ObjectId and display appropriately
+ Map map = (Map)value;
+ if (map.containsKey("_object_name"))
+ {
+ System.out.println(key + ": " + new ObjectId(map));
+ }
+ else
+ {
+ System.out.println(key + ": " + getString(value));
+ }
+ }
+ else
+ {
+ System.out.println(key + ": " + getString(value));
+ }
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java
new file mode 100644
index 0000000000..c81f674d1f
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfDescribed.java
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Subclass of QmfData.
+ * <p>
+ * When representing formally defined data, a QmfData instance is assigned a Schema.
+ *
+ * @author Fraser Adams
+ */
+public class QmfDescribed extends QmfData
+{
+ private SchemaClassId _schema_id;
+
+ /**
+ * The default constructor, initialises the underlying QmfData base class with an empty Map
+ */
+ protected QmfDescribed()
+ {
+ }
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+ *
+ * @param m the map used to construct the QmfDescribed
+ */
+ public QmfDescribed(final Map m)
+ {
+ super(m);
+ _schema_id = (m == null) ? null : new SchemaClassId((Map)m.get("_schema_id"));
+ }
+
+ /**
+ * Returns the SchemaClassId describing this object.
+ * @return the SchemaClassId describing this object.
+ */
+ public final SchemaClassId getSchemaClassId()
+ {
+ return _schema_id;
+ }
+
+ /**
+ * Sets the SchemaClassId describing this object.
+ * @param schema_id the SchemaClassId describing this object.
+ */
+ public final void setSchemaClassId(final SchemaClassId schema_id)
+ {
+ _schema_id = schema_id;
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ super.listValues();
+ _schema_id.listValues();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java
new file mode 100644
index 0000000000..06c19ca0ab
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEvent.java
@@ -0,0 +1,224 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * QMF supports event management functionality. An event is a notification that is sent by an Agent to alert Console(s)
+ * of a change in some aspect of the system under management. Like QMF Data, Events may be formally defined by a Schema
+ * or not. Unlike QMF Data, Events are not manageable entities - they have no lifecycle. Events simply indicate a point
+ * in time where some interesting action occurred.
+ * <p>
+ * An AMQP timestamp value is associated with each QmfEvent instance. It indicates the moment in time the event occurred.
+ * This timestamp is mandatory.
+ * <p>
+ * A severity level may be associated with each QmfEvent instance. The following severity levels are supported:
+ * <pre>
+ * * "emerg" - system is unusable
+ * * "alert" - action must be taken immediately
+ * * "crit" - the system is in a critical condition
+ * * "err" - there is an error condition
+ * * "warning" - there is a warning condition
+ * * "notice" - a normal but significant condition
+ * * "info" - a purely informational message
+ * * "debug" - messages generated to debug the application
+ * </pre>
+ * The default severity is "notice".
+ *
+ * @author Fraser Adams
+ */
+public final class QmfEvent extends QmfDescribed
+{
+ private static final String[] severities = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"};
+
+ private long _timestamp;
+ private int _severity;
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+ *
+ * @param m the map used to construct the QmfEvent
+ */
+ public QmfEvent(final Map m)
+ {
+ super(m);
+ _timestamp = m.containsKey("_timestamp") ? getLong(m.get("_timestamp")) : System.currentTimeMillis()*1000000l;
+ _severity = m.containsKey("_severity") ? (int)getLong(m.get("_severity")) : 5;
+ }
+
+ /**
+ * This constructor taking a SchemaEventClass is the main constructor used by Agents when creating Events
+ *
+ * @param schema the SchemaEventClass describing the Event
+ */
+ public QmfEvent(final SchemaEventClass schema)
+ {
+ _timestamp = System.currentTimeMillis()*1000000l;
+ setSchemaClassId(schema.getClassId());
+ }
+
+ /**
+ * Return the timestamp. Timestamps are recorded in nanoseconds since the epoch.
+ * <p>
+ * An AMQP timestamp value is associated with each QmfEvent instance. It indicates the moment in time the event
+ * occurred. This timestamp is mandatory.
+ *
+ * @return the AMQP timestamp value in nanoseconds since the epoch.
+ */
+ public long getTimestamp()
+ {
+ return _timestamp;
+ }
+
+ /**
+ * Return the severity.
+ * <p>
+ * A severity level may be associated with each QmfEvent instance. The following severity levels are supported:
+ * <pre>
+ * * "emerg" - system is unusable
+ * * "alert" - action must be taken immediately
+ * * "crit" - the system is in a critical condition
+ * * "err" - there is an error condition
+ * * "warning" - there is a warning condition
+ * * "notice" - a normal but significant condition
+ * * "info" - a purely informational message
+ * * "debug" - messages generated to debug the application
+ * </pre>
+ * The default severity is "notice"
+ *
+ * @return the severity value as a String as described above
+ */
+ public String getSeverity()
+ {
+ return severities[_severity];
+ }
+
+ /**
+ * Set the severity level of the Event
+ * @param severity the severity level of the Event as an int
+ */
+ public void setSeverity(final int severity)
+ {
+ if (severity < 0 || severity > 7)
+ {
+ // If supplied value is out of range we set to the default severity
+ _severity = 5;
+ return;
+ }
+ _severity = severity;
+ }
+
+ /**
+ * Set the severity level of the Event
+ * @param severity the severity level of the Event as a String.
+ * <p>
+ * The following severity levels are supported:
+ * <pre>
+ * * "emerg" - system is unusable
+ * * "alert" - action must be taken immediately
+ * * "crit" - the system is in a critical condition
+ * * "err" - there is an error condition
+ * * "warning" - there is a warning condition
+ * * "notice" - a normal but significant condition
+ * * "info" - a purely informational message
+ * * "debug" - messages generated to debug the application
+ * </pre>
+ */
+ public void setSeverity(final String severity)
+ {
+ for (int i = 0; i < severities.length; i++)
+ {
+ if (severity.equals(severities[i]))
+ {
+ _severity = i;
+ return;
+ }
+ }
+ // If we can't match the values we set to the default severity
+ _severity = 5;
+ }
+
+ /**
+ * Return the underlying Map representation of this QmfEvent
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("_values", super.mapEncode());
+ if (_subtypes != null)
+ {
+ map.put("_subtypes", _subtypes);
+ }
+ map.put("_schema_id", getSchemaClassId().mapEncode());
+ map.put("_timestamp", _timestamp);
+ map.put("_severity", _severity);
+ return map;
+ }
+
+ /**
+ * Helper/debug method to list the object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ System.out.println("QmfEvent:");
+ System.out.println(this);
+ }
+
+ /**
+ * Returns a String representation of the QmfEvent.
+ * <p>
+ * The String representation attempts to mirror the python class Event __repr__ method as far as possible.
+ * @return a String representation of the QmfEvent.
+ */
+ @Override
+ public String toString()
+ {
+ if (getSchemaClassId() == null)
+ {
+ return "<uninterpretable>";
+ }
+
+ String out = new Date(getTimestamp()/1000000l).toString();
+ out += " " + getSeverity() + " " + getSchemaClassId().getPackageName() + ":" + getSchemaClassId().getClassName();
+
+ StringBuilder buf = new StringBuilder();
+ for (Map.Entry<String, Object> entry : super.mapEncode().entrySet())
+ {
+ String disp = getString(entry.getValue());
+ if (disp.contains(" "))
+ {
+ disp = "\"" + disp + "\"";
+ }
+
+ buf.append(" " + entry.getKey() + "=" + disp);
+ }
+
+ return out + buf.toString();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java
new file mode 100644
index 0000000000..2e5b98852b
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfEventListener.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * A QmfEventListener object is used to receive asynchronously delivered WorkItems.
+ * <p>
+ * This provides an alternative (simpler) API to the official QMF2 WorkQueue API that some (including the Author)
+ * may prefer over the official API.
+ * <p>
+ * The following diagram illustrates the QmfEventListener Event model.
+ * <p>
+ * Notes
+ * <ol>
+ * <li>This is provided as an alternative to the official QMF2 WorkQueue and Notifier Event model.</li>
+ * <li>Agent and Console methods are sufficiently thread safe that it is possible to call them from a callback fired
+ * from the onEvent() method that may have been called from the JMS MessageListener. Internally the synchronous
+ * and asynchronous calls are processed on different JMS Sessions to facilitate this</li>
+ * </ol>
+ * <p>
+ * <img src="doc-files/QmfEventListenerModel.png"/>
+ *
+ * @author Fraser Adams
+ */
+public interface QmfEventListener extends QmfCallback
+{
+ /**
+ * Passes a WorkItem to the listener.
+ *
+ * @param item the WorkItem passed to the listener
+ */
+ public void onEvent(WorkItem item);
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java
new file mode 100644
index 0000000000..aa397e6116
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfException.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * A QmfException object
+ *
+ * @author Fraser Adams
+ */
+public class QmfException extends Exception
+{
+ private static final long serialVersionUID = 7526471155622776147L;
+
+ /**
+ * Create a QmfException with a given message String.
+ * @param message the message String.
+ */
+ public QmfException(String message)
+ {
+ super(message);
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java
new file mode 100644
index 0000000000..44dbcef9bf
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfManaged.java
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Map;
+
+/**
+ * Subclass of QmfDescribed, which is itself a subclass of QmfData.
+ * <p>
+ * When representing managed data, a QmfData instance is assigned an object identifier
+ *
+ * @author Fraser Adams
+ */
+public class QmfManaged extends QmfDescribed
+{
+ private ObjectId _object_id;
+
+ /**
+ * The default constructor, initialises the underlying QmfData base class with an empty Map
+ */
+ protected QmfManaged()
+ {
+ }
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+ *
+ * @param m the map used to construct the QmfManaged
+ */
+ public QmfManaged(final Map m)
+ {
+ super(m);
+ _object_id = (m == null) ? null : new ObjectId((Map)m.get("_object_id"));
+ }
+
+ /**
+ * Returns the ObjectId of this managed object.
+ * @return the ObjectId of this managed object.
+ */
+ public final ObjectId getObjectId()
+ {
+ return _object_id;
+ }
+
+ /**
+ * Sets the ObjectId of this managed object.
+ * @param object_id the ObjectId of this managed object.
+ */
+ public final void setObjectId(final ObjectId object_id)
+ {
+ _object_id = object_id;
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ super.listValues();
+ System.out.println("_object_id: " + getObjectId());
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java
new file mode 100644
index 0000000000..2ec69c9607
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQuery.java
@@ -0,0 +1,343 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+// Reuse this class as it provides a handy mechanism to parse an predicate String into a Map
+import org.apache.qpid.messaging.util.AddressParser;
+
+/**
+ * A Query is a mechanism for interrogating the management database. A Query represents a selector which is sent to
+ * an Agent. The Agent applies the Query against its management database, and returns those objects which meet the
+ * constraints described in the query.
+ * <p>
+ * A Query must specify the class of information it is selecting. This class of information is considered the target
+ * of the query. Any data objects selected by the query will be of the type indicated by the target.
+ * <p>
+ * A Query may also specify a selector which is used as a filter against the set of all target instances. Only those
+ * instances accepted by the filter will be returned in response to the query.
+ * <p>
+ * N.B. There appear to be a number of differences in the description of the map encoding of a Query between the
+ * QMF2 API specified at <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a> and the
+ * QMF2 protocol that is specified at <a href=https://cwiki.apache.org/qpid/qmf-map-message-protocol.html>QMF Map
+ * Message Protocol</a> in particular the use of the underscore to specify key names e.g. "_what", "_where",
+ * "_object_id", "_schema_id".
+ * <p>
+ * This implementation trusts the protocol specification more than the API specification as the underscores are more
+ * consistent with the rest of the protocol and the underscored variants are what have been observed when querying
+ * the broker ManagementAgent.
+ * <p>
+ * A QmfQuery may be constructed as either an "ID" query (to query for a specific ObjectId or SchemaClassId) or a
+ * "PREDICATE" query (to query based upon an expression). Note that QMF considers string arguments in boolean
+ * expressions to be names of data values in the target object. When evaluating a predicate expression, QMF will fetch
+ * the value of the named data item from each candidate target object. The value is then used in the boolean expression.
+ * In other words, QMF considers string arguments to be variables in the expression. In order to indicate that a string
+ * should be treated as a literal instead, the string must be quoted using the "quote" expression.
+ * <p>
+ * <b>Examples</b>
+ * <p>
+ * Assume a QmfData type defines fields named "name", "address" and "town". The following predicate expression matches
+ * any instance with a name field set to "tross", or any instance where the name field is "jross", the address field is
+ * "1313 Spudboy Lane" and the town field is "Utopia":
+ * <p>
+ * <pre>
+ * ["or" ["eq" "name" ["quote" "tross"]]
+ * ["and" ["eq" "name" ["quote" "jross"]]
+ * ["eq" "address" ["quote" "1313 Spudboy Lane"]]
+ * ["eq" ["quote" "Utopia"] "town"]
+ * ]
+ * ]
+ * </pre>
+ * Assume a QmfData type with fields "name" and "age". A predicate to find all instances with name matching the regular
+ * expression "?ross" with an optional age field that is greater than the value 29 or less than 12 would be:
+ * <pre>
+ * ["and" ["re_match" "name" ["quote" "?ross"]]
+ * ["and" ["exists" "age"]
+ * ["or" ["gt" "age" 27] ["lt" "age" 12]]
+ * ]
+ * ]
+ * </pre>
+ * <p>
+ * The Expression structure is illustrated below in the context of its relationship with QmfQuery.
+ * <img src="doc-files/QmfQuery.png"/>
+ *
+ *
+ * @author Fraser Adams
+ */
+public final class QmfQuery extends QmfData
+{
+ public static final QmfQuery ID = new QmfQuery();
+ public static final QmfQuery PREDICATE = new QmfQuery();
+
+ private QmfQueryTarget _target;
+ private SchemaClassId _classId;
+ private String _packageName;
+ private String _className;
+ private ObjectId _objectId;
+ private List _predicate;
+ private Expression _expression;
+
+ /**
+ * This Constructor is only used to construct the ID and PREDICATE objects
+ */
+ private QmfQuery()
+ {
+ }
+
+ /**
+ * Construct an QmfQuery with no Selector from a QmfQueryTarget
+ * @param target the query target
+ */
+ public QmfQuery(final QmfQueryTarget target)
+ {
+ _target = target;
+ setValue("_what", _target.toString());
+ }
+
+ /**
+ * Construct an ID QmfQuery from a QmfQueryTarget and SchemaClassId
+ * @param target the query target
+ * @param classId the SchemaClassId to evaluate against
+ */
+ public QmfQuery(final QmfQueryTarget target, final SchemaClassId classId)
+ {
+ _target = target;
+ _classId = classId;
+ _packageName = _classId.getPackageName();
+ _className = _classId.getClassName();
+ setValue("_what", _target.toString());
+ setValue("_schema_id", _classId.mapEncode());
+ }
+
+ /**
+ * Construct an ID QmfQuery from a QmfQueryTarget and ObjectId
+ * @param target the query target
+ * @param objectId the ObjectId to evaluate against
+ */
+ public QmfQuery(final QmfQueryTarget target, final ObjectId objectId)
+ {
+ _target = target;
+ _objectId = objectId;
+ setValue("_what", _target.toString());
+ setValue("_object_id", _objectId.mapEncode());
+ }
+
+ /**
+ * Construct a PREDICATE QmfQuery from a QmfQueryTarget and predicate String
+ * @param target the query target
+ * @param predicateString the predicate to evaluate against
+ */
+ public QmfQuery(final QmfQueryTarget target, final String predicateString) throws QmfException
+ {
+ _target = target;
+
+ if (predicateString.charAt(0) == '[')
+ {
+ Map predicateMap = new AddressParser("{'_where': " + predicateString + "}").map();
+ _predicate = (List)predicateMap.get("_where");
+ _expression = Expression.createExpression(_predicate);
+ }
+ else
+ {
+ throw new QmfException("Invalid predicate format");
+ }
+
+ setValue("_what", _target.toString());
+ setValue("_where", _predicate);
+ }
+
+ /**
+ * Construct a QmfQuery from a Map encoding
+ * @param m encoding the query
+ */
+ public QmfQuery(final Map m) throws QmfException
+ {
+ super(m);
+
+ _target = QmfQueryTarget.valueOf(getStringValue("_what"));
+
+ if (hasValue("_object_id"))
+ {
+ _objectId = getRefValue("_object_id");
+ }
+
+ if (hasValue("_schema_id"))
+ {
+ _classId = new SchemaClassId((Map)getValue("_schema_id"));
+ _packageName = _classId.getPackageName();
+ _className = _classId.getClassName();
+ }
+
+ if (hasValue("_where"))
+ {
+ _predicate = (List)getValue("_where");
+ _expression = Expression.createExpression(_predicate);
+ }
+ }
+
+ /**
+ * Return target name.
+ * @return target name.
+ */
+ public QmfQueryTarget getTarget()
+ {
+ return _target;
+ }
+
+ /**
+ * Undefined by QMF2 API.
+ * <p>
+ * According to <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Specification</a>
+ * "The value of the <target name string> map entry is ignored for now, its use is TBD."
+ * so this method returns a null Map.
+ */
+ public Map getTargetParam()
+ {
+ return null;
+ }
+
+ /**
+ * Return QmfQuery.ID or QmfQuery.PREDICATE or null if there is no Selector
+ * @return QmfQuery.ID or QmfQuery.PREDICATE or null if there is no Selector
+ */
+ public QmfQuery getSelector()
+ {
+ if (_predicate == null)
+ {
+ if (_objectId == null && _classId == null)
+ {
+ return null;
+ }
+ return ID;
+ }
+ return PREDICATE;
+ }
+
+ /**
+ * Return predicate expression if selector type is QmfQuery.PREDICATE
+ * @return predicate expression if selector type is QmfQuery.PREDICATE
+ */
+ public List getPredicate()
+ {
+ return _predicate;
+ }
+
+ /**
+ * Return the SchemaClassId if selector type is QmfQuery.ID
+ * @return the SchemaClassId if selector type is QmfQuery.ID
+ */
+ public SchemaClassId getSchemaClassId()
+ {
+ return _classId;
+ }
+
+ /**
+ * Return the ObjectId if selector type is QmfQuery.ID
+ * @return the ObjectId if selector type is QmfQuery.ID
+ */
+ public ObjectId getObjectId()
+ {
+ return _objectId;
+ }
+
+ /**
+ * Evaluate query against a QmfData instance.
+ * @return true if query matches the QmfData instance, else false.
+ */
+ public boolean evaluate(final QmfData data)
+ {
+ if (_predicate == null)
+ {
+ if (data instanceof QmfManaged)
+ {
+ QmfManaged managedData = (QmfManaged)data;
+ // Evaluate an ID query on Managed Data
+ if (_objectId != null && _objectId.equals(managedData.getObjectId()))
+ {
+ return true;
+ }
+ else if (_classId != null)
+ {
+ SchemaClassId dataClassId = managedData.getSchemaClassId();
+ String dataClassName = dataClassId.getClassName();
+ String dataPackageName = dataClassId.getPackageName();
+
+ // Wildcard the package name if it hasn't been specified when checking class name
+ if (_className.equals(dataClassName) &&
+ (_packageName.length() == 0 || _packageName.equals(dataPackageName)))
+ {
+ return true;
+ }
+
+ // Wildcard the class name if it hasn't been specified when checking package name
+ if (_packageName.equals(dataPackageName) &&
+ (_className.length() == 0 || _className.equals(dataClassName)))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ else
+ {
+ // Evaluate a PREDICATE query by evaluating against the expression created from the predicate
+ if (_predicate.size() == 0)
+ {
+ return true;
+ }
+
+ return _expression.evaluate(data);
+ }
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ System.out.println("QmfQuery:");
+ System.out.println("target: " + _target);
+ if (_predicate != null)
+ {
+ System.out.println("selector: QmfQuery.PREDICATE");
+ System.out.println("predicate: " + _predicate);
+ }
+ else if (_classId != null)
+ {
+ System.out.println("selector: QmfQuery.ID");
+ _classId.listValues();
+ }
+ else if (_objectId != null)
+ {
+ System.out.println("selector: QmfQuery.ID");
+ System.out.println(_objectId);
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java
new file mode 100644
index 0000000000..01aba88bfc
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfQueryTarget.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * An enum containing the QMF type code indicating a QMF query target defined in
+ * <a href=https://cwiki.apache.org/qpid/qmf-map-message-protocol.html>QMF Map Message Protocol</a>
+ *
+ * @author Fraser Adams
+ */
+public enum QmfQueryTarget
+{
+ SCHEMA_ID,
+ SCHEMA,
+ OBJECT_ID,
+ OBJECT;
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java
new file mode 100644
index 0000000000..a19ebcf393
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/QmfType.java
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.qmf2.common;
+
+/**
+ * An enum containing the QMF type code indicating a QMF object's data type
+ *
+ * @author Fraser Adams
+ */
+public enum QmfType
+{
+ TYPE_VOID,
+ TYPE_BOOL,
+ TYPE_INT,
+ TYPE_FLOAT,
+ TYPE_STRING,
+ TYPE_MAP,
+ TYPE_LIST,
+ TYPE_UUID;
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java
new file mode 100644
index 0000000000..b15a1a5c96
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClass.java
@@ -0,0 +1,135 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Subclass of QmfData
+ * <p>
+ * When representing formally defined data, a QmfData instance is assigned a Schema.
+ * <p>
+ * The following diagram illustrates the QMF2 Schema class hierarchy.
+ * <p>
+ * <img src="doc-files/Schema.png"/>
+ *
+ * @author Fraser Adams
+ */
+public class SchemaClass extends QmfData
+{
+ public static final SchemaClass EMPTY_SCHEMA = new SchemaClass();
+
+ private SchemaClassId _classId;
+
+ /**
+ * The default constructor, initialises the underlying QmfData base class with an empty Map
+ */
+ protected SchemaClass()
+ {
+ }
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter.
+ *
+ * @param m the map used to construct the SchemaClass
+ */
+ public SchemaClass(final Map m)
+ {
+ super(m);
+ _classId = new SchemaClassId((Map)getValue("_schema_id"));
+ }
+
+ /**
+ * Return the SchemaClassId that identifies this Schema instance.
+ * @return the SchemaClassId that identifies this Schema instance.
+ */
+ public final SchemaClassId getClassId()
+ {
+ if (_classId.getHashString() == null)
+ {
+ _classId = new SchemaClassId(_classId.getPackageName(),
+ _classId.getClassName(),
+ _classId.getType(),
+ generateHash());
+ }
+ return _classId;
+ }
+
+ /**
+ * Set the SchemaClassId that identifies this Schema instance.
+ * @param cid the SchemaClassId that identifies this Schema instance.
+ */
+ public final void setClassId(final SchemaClassId cid)
+ {
+ _classId = cid;
+ }
+
+ /**
+ * Return a hash generated over the body of the schema, and return a representation of the hash
+ * @return a hash generated over the body of the schema, and return a representation of the hash
+ */
+ public final UUID generateHash()
+ {
+ try
+ {
+ MessageDigest md5 = MessageDigest.getInstance("MD5");
+ updateHash(md5);
+ return UUID.nameUUIDFromBytes(md5.digest());
+ }
+ catch (NoSuchAlgorithmException nsae)
+ {
+ }
+ return null;
+ }
+
+ /**
+ * Generate the partial hash for the schema fields in this base class
+ * @param md5 the MessageDigest to be updated
+ */
+ protected void updateHash(MessageDigest md5)
+ {
+ try
+ {
+ md5.update(_classId.getPackageName().getBytes("UTF-8"));
+ md5.update(_classId.getClassName().getBytes("UTF-8"));
+ md5.update(_classId.getType().getBytes("UTF-8"));
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ }
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ super.listValues();
+ _classId.listValues();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java
new file mode 100644
index 0000000000..5ad4ba8249
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaClassId.java
@@ -0,0 +1,202 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Schema are identified by a combination of their package name and class name. A hash value over the body of
+ * the schema provides a revision identifier. The class SchemaClassId represents this Schema identifier.
+ * <p>
+ * If the hash value is not supplied, then the value of the hash string will be set to None. This will be the
+ * case when a SchemaClass is being dynamically constructed, and a proper hash is not yet available.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaClassId extends QmfData
+{
+ private String _packageName = "";
+ private String _className = "";
+ private String _type = "";
+ private UUID _hash = null;
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter.
+ *
+ * @param m the map used to construct the SchemaClassId.
+ */
+ public SchemaClassId(final Map m)
+ {
+ super(m);
+ _packageName = getStringValue("_package_name");
+ _className = getStringValue("_class_name");
+ _type = getStringValue("_type");
+ _hash = hasValue("_hash") ? (UUID)getValue("_hash") : null;
+ }
+
+ /**
+ * Construct a SchemaClassId from a given class name.
+ *
+ * @param className the class name.
+ */
+ public SchemaClassId(final String className)
+ {
+ this(null, className, null, null);
+ }
+
+ /**
+ * Construct a SchemaClassId from a given package name and class name.
+ *
+ * @param packageName the package name.
+ * @param className the class name.
+ */
+ public SchemaClassId(final String packageName, final String className)
+ {
+ this(packageName, className, null, null);
+ }
+
+ /**
+ * Construct a SchemaClassId from a given package name and class name and type (_data or _event).
+ *
+ * @param packageName the package name.
+ * @param className the class name.
+ * @param type the schema type (_data or _event).
+ */
+ public SchemaClassId(final String packageName, final String className, final String type)
+ {
+ this(packageName, className, type, null);
+ }
+
+ /**
+ * Construct a SchemaClassId from a given package name and class name, type (_data or _event) and hash.
+ *
+ * @param packageName the package name.
+ * @param className the class name.
+ * @param type the schema type (_data or _event).
+ * @param hash a UUID representation of the md5 hash of the Schema,
+ */
+ public SchemaClassId(final String packageName, final String className, final String type, final UUID hash)
+ {
+ if (packageName != null)
+ {
+ setValue("_package_name", packageName);
+ _packageName = packageName;
+ }
+
+ if (className != null)
+ {
+ setValue("_class_name", className);
+ _className = className;
+ }
+
+ if (type != null)
+ {
+ setValue("_type", type);
+ _type = type;
+ }
+
+ if (hash != null)
+ {
+ setValue("_hash", hash);
+ _hash = hash;
+ }
+ }
+
+ /**
+ * Return The name of the associated package.
+ * @return The name of the associated package. Returns empty String if there's no package name.
+ */
+ public String getPackageName()
+ {
+ return _packageName;
+ }
+
+ /**
+ * Return The name of the class within the package.
+ * @return The name of the class within the package. Returns empty String if there's no class name.
+ */
+ public String getClassName()
+ {
+ return _className;
+ }
+
+ /**
+ * Return The type of schema, either "_data" or "_event".
+ * @return The type of schema, either "_data" or "_event". Returns empty String if type is unknown.
+ */
+ public String getType()
+ {
+ return _type;
+ }
+
+ /**
+ * Return The MD5 hash of the schema.
+ * @return The MD5 hash of the schema, in the format "%08x-%08x-%08x-%08x"
+ */
+ public UUID getHashString()
+ {
+ return _hash;
+ }
+
+ /**
+ * Compares two SchemaClassId objects for equality.
+ * @param rhs the right hands side SchemaClassId in the comparison.
+ * @return true if the two SchemaClassId objects are equal otherwise returns false.
+ */
+ @Override
+ public boolean equals(final Object rhs)
+ {
+ if (rhs instanceof SchemaClassId)
+ {
+ SchemaClassId that = (SchemaClassId)rhs;
+ String lvalue = _packageName + _className + _hash;
+ String rvalue = that._packageName + that._className + that._hash;
+ return lvalue.equals(rvalue);
+ }
+ return false;
+ }
+
+ /**
+ * Returns the SchemaClassId hashCode.
+ * @return the SchemaClassId hashCode.
+ */
+ @Override
+ public int hashCode()
+ {
+ String lvalue = _packageName + _className + _hash;
+ return lvalue.hashCode();
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ System.out.println("_package_name: " + getPackageName());
+ System.out.println("_class_name: " + getClassName());
+ System.out.println("_type: " + getType());
+ System.out.println("_hash: " + getHashString());
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java
new file mode 100644
index 0000000000..229f988dc7
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaEventClass.java
@@ -0,0 +1,266 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Subclass of SchemaClass
+ * <p>
+ * Agent applications may dynamically construct instances of these objects by adding properties at run
+ * time. However, once the Schema is made public, it must be considered immutable, as the hash value
+ * must be constant once the Schema is in use.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that the
+ * properties are represented by an unordered map of SchemaProperty entries indexed by property name, however
+ * these are actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe the
+ * schema event's properties.
+ * <p>
+ * In this implementation getProperties() returns a List<SchemaProperty> reflecting the reality of the protocol
+ * rather than what is suggested by the API documentation.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaEventClass extends SchemaClass
+{
+ private List<SchemaProperty> _properties = new ArrayList<SchemaProperty>();
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter.
+ *
+ * @param m the map used to construct the SchemaEventClass
+ */
+ public SchemaEventClass(final Map m)
+ {
+ super(m);
+ if (m != null)
+ {
+ List<Map> mapEncodedProperties = this.<List<Map>>getValue("_properties");
+ if (mapEncodedProperties != null)
+ { // In theory this shouldn't be null as "_properties" property of SchemaClass is not optional but.....
+ for (Map property : mapEncodedProperties)
+ {
+ addProperty(new SchemaProperty(property));
+ }
+ }
+ }
+ }
+
+ /**
+ * Construct a SchemaEventClass from a package name and a class name.
+ *
+ * @param packageName the package name.
+ * @param className the class name.
+ */
+ public SchemaEventClass(final String packageName, final String className)
+ {
+ setClassId(new SchemaClassId(packageName, className, "_event"));
+ }
+
+ /**
+ * Construct a SchemaEventClass from a SchemaClassId.
+ *
+ * @param classId the SchemaClassId identifying this Schema.
+ */
+ public SchemaEventClass(final SchemaClassId classId)
+ {
+ setClassId(new SchemaClassId(classId.getPackageName(), classId.getClassName(), "_event"));
+ }
+
+ /**
+ * Return optional default severity of this Property.
+ * @return optional default severity of this Property.
+ */
+ public long getDefaultSeverity()
+ {
+ return getLongValue("_default_severity");
+ }
+
+ /**
+ * Set the default severity of this Schema Event
+ *
+ * @param severity optional severity of this Schema Event.
+ */
+ public void setDefaultSeverity(final int severity)
+ {
+ setValue("_default_severity", severity);
+ }
+
+ /**
+ * Return optional string description of this Schema Event.
+ * @return optional string description of this Schema Event.
+ */
+ public String getDesc()
+ {
+ return getStringValue("_desc");
+ }
+
+ /**
+ * Set the optional string description of this Schema Object.
+ *
+ * @param description optional string description of this Schema Object.
+ */
+ public void setDesc(final String description)
+ {
+ setValue("_desc", description);
+ }
+
+ /**
+ * Return the count of SchemaProperties in this instance.
+ * @return the count of SchemaProperties in this instance.
+ */
+ public long getPropertyCount()
+ {
+ return getProperties().size();
+ }
+
+ /**
+ * Return Schema Object's properties.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+ * the properties are represented by an unordered map of SchemaProperty indexed by property name however it
+ * is actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe the
+ * schema objects's properties. In this implementation getProperties() returns a List<SchemaProperty>
+ * reflecting the reality of the protocol rather than what is suggested by the API documentation.
+ *
+ * @return Schema Object's properties.
+ */
+ public List<SchemaProperty> getProperties()
+ {
+ return _properties;
+ }
+
+ /**
+ * Return the SchemaProperty for the parameter "name".
+ * @param name the name of the SchemaProperty to return.
+ * @return the SchemaProperty for the parameter "name".
+ */
+ public SchemaProperty getProperty(final String name)
+ {
+ for (SchemaProperty p : _properties)
+ {
+ if (p.getName().equals(name))
+ {
+ return p;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the SchemaProperty for the index i.
+ * @param i the index of the SchemaProperty to return.
+ * @return the SchemaProperty for the index i.
+ */
+ public SchemaProperty getProperty(final int i)
+ {
+ return _properties.get(i);
+ }
+
+ /**
+ * Add a new Property.
+ *
+ * @param name the name of the SchemaProperty
+ * @param value the SchemaProperty associated with "name"
+ */
+ public void addProperty(final String name, final SchemaProperty value)
+ {
+ value.setValue("_name", name);
+ _properties.add(value);
+ }
+
+ /**
+ * Add a new Property.
+ *
+ * @param value the SchemaProperty associated with "name"
+ */
+ public void addProperty(final SchemaProperty value)
+ {
+ _properties.add(value);
+ }
+
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ System.out.println("SchemaEventClass:");
+ getClassId().listValues();
+
+ if (hasValue("_desc")) System.out.println("desc: " + getDesc());
+ if (hasValue("_default_severity")) System.out.println("default severity: " + getDefaultSeverity());
+
+ if (getPropertyCount() > 0)
+ {
+ System.out.println("properties:");
+ }
+ for (SchemaProperty p : _properties)
+ {
+ p.listValues();
+ }
+ }
+
+ /**
+ * Return the underlying map.
+ * <p>
+ * We need to convert any properties from SchemaProperty to Map.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ // I think a "_methods" property is mandatory for a SchemaClass even if it's empty
+ setValue("_methods", Collections.EMPTY_LIST);
+ List<Map> mapEncodedProperties = new ArrayList<Map>();
+ for (SchemaProperty p : _properties)
+ {
+ mapEncodedProperties.add(p.mapEncode());
+ }
+ setValue("_properties", mapEncodedProperties);
+ setValue("_schema_id", getClassId().mapEncode());
+ return super.mapEncode();
+ }
+
+ /**
+ * Generate the partial hash for the schema fields in this class.
+ * @param md5 the MessageDigest to be updated.
+ */
+ @Override
+ protected void updateHash(MessageDigest md5)
+ {
+ super.updateHash(md5);
+
+ for (SchemaProperty p : _properties)
+ {
+ p.updateHash(md5);
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java
new file mode 100644
index 0000000000..d4568dcb6e
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaMethod.java
@@ -0,0 +1,275 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The SchemaMethod class describes a method call's parameter list.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+ * the parameter list is represented by an unordered map of SchemaProperty entries indexed by parameter name,
+ * however is is actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe
+ * the method's arguments".
+ * <p>
+ * In this implementation getArguments() returns a List<SchemaProperty> reflecting the reality of the protocol
+ * rather than what is suggested by the API documentation.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaMethod extends QmfData
+{
+ private List<SchemaProperty> _arguments = new ArrayList<SchemaProperty>();
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter.
+ *
+ * @param m the map used to construct the SchemaMethod.
+ */
+ public SchemaMethod(final Map m)
+ {
+ super(m);
+ if (m != null)
+ {
+ List<Map> mapEncodedArguments = this.<List<Map>>getValue("_arguments");
+ if (mapEncodedArguments != null)
+ { // In theory this shouldn't be null as "_arguments" property of SchemaMethod is not optional but.....
+ for (Map argument : mapEncodedArguments)
+ {
+ addArgument(new SchemaProperty(argument));
+ }
+ }
+ }
+ }
+
+ /**
+ * Construct a SchemaMethod from its name.
+ *
+ * @param name the name of the SchemaMethod.
+ */
+ public SchemaMethod(final String name)
+ {
+ this(name, null);
+ }
+
+ /**
+ * Construct a SchemaMethod from its name and description.
+ *
+ * @param name the name of the SchemaMethod.
+ * @param description a description of the SchemaMethod.
+ */
+ public SchemaMethod(final String name, final String description)
+ {
+ setValue("_name", name);
+
+ if (description != null)
+ {
+ setValue("_desc", description);
+ }
+ }
+
+ /**
+ * Construct a SchemaMethod from a map of "name":<SchemaProperty> entries and description.
+ *
+ * Note this Constructor is the one given in the QMF2 API specification at
+ * <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a>Note too that this method does not
+ * set a name so setName() needs to be called explicitly by clients after construction.
+ *
+ * @param args a Map of "name":<SchemaProperty> entries.
+ * @param description a description of the SchemaMethod.
+ */
+ public SchemaMethod(final Map<String, SchemaProperty> args, final String description)
+ {
+ if (description != null)
+ {
+ setValue("_desc", description);
+ }
+
+ for (Map.Entry<String, SchemaProperty> entry : args.entrySet())
+ {
+ addArgument(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /**
+ * Return the method's name.
+ * @return the method's name.
+ */
+ public String getName()
+ {
+ return getStringValue("_name");
+ }
+
+ /**
+ * Sets the method's name.
+ * @param name the method's name.
+ */
+ public void setName(final String name)
+ {
+ setValue("_name", name);
+ }
+
+ /**
+ * Return a description of the method.
+ * @return a description of the method.
+ */
+ public String getDesc()
+ {
+ return getStringValue("_desc");
+ }
+
+ /**
+ * Return the number of arguments for this method.
+ * @return the number of arguments for this method.
+ */
+ public int getArgumentCount()
+ {
+ return getArguments().size();
+ }
+
+ /**
+ * Return the Method's arguments.
+ *<p>
+ * <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+ * the parameter list is represented by an unordered map of SchemaProperty entries indexed by parameter name,
+ * however is is actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe
+ * the method's arguments". In this implementation getArguments() returns a List<SchemaProperty> reflecting the
+ * reality of the protocol rather than what is suggested by the API documentation.
+ *
+ * @return the Method's arguments.
+ */
+ public List<SchemaProperty> getArguments()
+ {
+ return _arguments;
+ }
+
+ /**
+ * Return the argument with the name "name" as a SchemaProperty.
+ * @param name the name of the SchemaProperty to return.
+ * @return the argument with the name "name" as a SchemaProperty.
+ */
+ public SchemaProperty getArgument(final String name)
+ {
+ for (SchemaProperty p : _arguments)
+ {
+ if (p.getName().equals(name))
+ {
+ return p;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the argument for the index i as a SchemaProperty.
+ * @param i the index of the SchemaProperty to return.
+ * @return the argument for the index i as a SchemaProperty.
+ */
+ public SchemaProperty getArgument(final int i)
+ {
+ return _arguments.get(i);
+ }
+
+ /**
+ * Add a new method argument.
+ *
+ * @param name the name of the SchemaProperty.
+ * @param value the SchemaProperty to add.
+ */
+ public void addArgument(final String name, final SchemaProperty value)
+ {
+ value.setValue("_name", name);
+ _arguments.add(value);
+ }
+
+ /**
+ * Add a new method argument.
+ *
+ * @param value the SchemaProperty to add.
+ */
+ public void addArgument(final SchemaProperty value)
+ {
+ _arguments.add(value);
+ }
+
+ /**
+ * Return the underlying map.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ List<Map> args = new ArrayList<Map>();
+ for (SchemaProperty p : _arguments)
+ {
+ args.add(p.mapEncode());
+ }
+ setValue("_arguments", args);
+
+ return super.mapEncode();
+ }
+
+ /**
+ * Generate the partial hash for the schema fields in this class.
+ * @param md5 the MessageDigest to be updated.
+ */
+ protected void updateHash(MessageDigest md5)
+ {
+ try
+ {
+ md5.update(getName().getBytes("UTF-8"));
+ md5.update(getDesc().toString().getBytes("UTF-8"));
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ }
+ for (SchemaProperty p : _arguments)
+ {
+ p.updateHash(md5);
+ }
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ System.out.println("SchemaMethod:");
+ System.out.println("_name: " + getName());
+ if (hasValue("_desc")) System.out.println("_desc: " + getDesc());
+ if (getArgumentCount() > 0)
+ {
+ System.out.println("_arguments:");
+ }
+ for (SchemaProperty p : _arguments)
+ {
+ p.listValues();
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaObjectClass.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaObjectClass.java
new file mode 100644
index 0000000000..54812fab71
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaObjectClass.java
@@ -0,0 +1,378 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.security.MessageDigest;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Subclass of SchemaClass.
+ * <p>
+ * The structure of QmfData objects is formally defined by the class SchemaObjectClass.
+ * <p>
+ * Agent applications may dynamically construct instances of these objects by adding properties and methods
+ * at run time. However, once the Schema is made public, it must be considered immutable, as the hash value
+ * must be constant once the Schema is in use.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+ * the properties and methods are represented by an unordered map of SchemaProperty or SchemaMethod entries indexed by
+ * property or method name, however these are actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY
+ * and "List of SCHEMA_METHOD" elements that describe the schema objects's properties and methods". In this
+ * implementation getProperties() returns a List<SchemaProperty> and getMethods() returns a List<SchemaMethod>
+ * reflecting the reality of the protocol rather than what is suggested by the API documentation.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaObjectClass extends SchemaClass
+{
+ private List<SchemaMethod> _methods = new ArrayList<SchemaMethod>();
+ private List<SchemaProperty> _properties = new ArrayList<SchemaProperty>();
+ private String[] _idNames = {};
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter.
+ *
+ * @param m the map used to construct the SchemaObjectClass.
+ */
+ public SchemaObjectClass(final Map m)
+ {
+ super(m);
+ if (m != null)
+ {
+ List<Map> mapEncodedMethods = this.<List<Map>>getValue("_methods");
+ if (mapEncodedMethods != null)
+ { // In theory this shouldn't be null as "_methods" property of SchemaClass is not optional but.....
+ for (Map method : mapEncodedMethods)
+ {
+ addMethod(new SchemaMethod(method));
+ }
+ }
+
+ List<Map> mapEncodedProperties = this.<List<Map>>getValue("_properties");
+ if (mapEncodedProperties != null)
+ { // In theory this shouldn't be null as "_properties" property of SchemaClass is not optional but.....
+ for (Map property : mapEncodedProperties)
+ {
+ addProperty(new SchemaProperty(property));
+ }
+ }
+ }
+ }
+
+ /**
+ * Construct a SchemaObjectClass from a package name and a class name.
+ *
+ * @param packageName the package name.
+ * @param className the class name.
+ */
+ public SchemaObjectClass(final String packageName, final String className)
+ {
+ setClassId(new SchemaClassId(packageName, className, "_data"));
+ }
+
+ /**
+ * Construct a SchemaObjectClass from a SchemaClassId.
+ *
+ * @param classId the SchemaClassId identifying this SchemaObjectClass.
+ */
+ public SchemaObjectClass(final SchemaClassId classId)
+ {
+ setClassId(new SchemaClassId(classId.getPackageName(), classId.getClassName(), "_data"));
+ }
+
+ /**
+ * Return optional string description of this Schema Object.
+ * @return optional string description of this Schema Object.
+ */
+ public String getDesc()
+ {
+ return getStringValue("_desc");
+ }
+
+ /**
+ * Set the Schema Object's description.
+ *
+ * @param description optional string description of this Schema Object.
+ */
+ public void setDesc(final String description)
+ {
+ setValue("_desc", description);
+ }
+
+ /**
+ * Return the list of property names to use when constructing the object identifier.
+ * <p>
+ * Get the value of the list of property names to use when constructing the object identifier.
+ * When a QmfAgentData object is created the values of the properties specified here are used to
+ * create the associated ObjectId object name.
+ * @return the list of property names to use when constructing the object identifier.
+ */
+ public String[] getIdNames()
+ {
+ // As it's not performance critical copy _idNames, because "return _idNames;" causes findBugs to moan.
+ return Arrays.copyOf(_idNames, _idNames.length);
+ }
+
+ /**
+ * Return the count of SchemaProperties in this instance.
+ * @return the count of SchemaProperties in this instance.
+ */
+ public long getPropertyCount()
+ {
+ return getProperties().size();
+ }
+
+ /**
+ * Return Schema Object's properties.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+ * the properties are represented by an unordered map of SchemaProperty indexed by property name, however it
+ * is actually represented in the QMF2 protocol as a "List of SCHEMA_PROPERTY elements that describe the
+ * schema objects's properties. In this implementation getProperties() returns a List<SchemaProperty>
+ * reflecting the reality of the protocol rather than what is suggested by the API documentation.
+ *
+ * @return Schema Object's properties.
+ */
+ public List<SchemaProperty> getProperties()
+ {
+ return _properties;
+ }
+
+ /**
+ * Return the SchemaProperty for the parameter "name".
+ * @param name the name of the SchemaProperty to return.
+ * @return the SchemaProperty for the parameter "name".
+ */
+ public SchemaProperty getProperty(final String name)
+ {
+ for (SchemaProperty p : _properties)
+ {
+ if (p.getName().equals(name))
+ {
+ return p;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the SchemaProperty for the index i.
+ * @param i the index of the SchemaProperty to return.
+ * @return the SchemaProperty for the index i.
+ */
+ public SchemaProperty getProperty(final int i)
+ {
+ return _properties.get(i);
+ }
+
+ /**
+ * Return the count of SchemaMethod's in this instance.
+ * @return the count of SchemaMethod's in this instance.
+ */
+ public long getMethodCount()
+ {
+ return getMethods().size();
+ }
+
+ /**
+ * Return Schema Object's methods.
+ * <p>
+ * Note that <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API</a> suggests that
+ * the methods are represented by an unordered map of SchemaMethod indexed by method name, however it
+ * is actually represented in the QMF2 protocol as a "List of SCHEMA_METHOD elements that describe the
+ * schema objects's methods. In this implementation getMethods() returns a List<SchemaMethod>
+ * reflecting the reality of the protocol rather than what is suggested by the API documentation.
+ *
+ * @return Schema Object's methods.
+ */
+ public List<SchemaMethod> getMethods()
+ {
+ return _methods;
+ }
+
+ /**
+ * Return the SchemaMethod for the parameter "name".
+ * @param name the name of the SchemaMethod to return.
+ * @return the SchemaMethod for the parameter "name".
+ */
+ public SchemaMethod getMethod(final String name)
+ {
+ for (SchemaMethod m : _methods)
+ {
+ if (m.getName().equals(name))
+ {
+ return m;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the SchemaMethod for the index i.
+ * @param i the index of the SchemaMethod to return.
+ * @return the SchemaMethod for the index i.
+ */
+ public SchemaMethod getMethod(final int i)
+ {
+ return _methods.get(i);
+ }
+
+ /**
+ * Add a new Property.
+ *
+ * @param name the name of the SchemaProperty.
+ * @param value the SchemaProperty associated with "name".
+ */
+ public void addProperty(final String name, final SchemaProperty value)
+ {
+ value.setValue("_name", name);
+ _properties.add(value);
+ }
+
+ /**
+ * Add a new Property.
+ *
+ * @param value the SchemaProperty associated with "name".
+ */
+ public void addProperty(final SchemaProperty value)
+ {
+ _properties.add(value);
+ }
+
+ /**
+ * Add a new Method.
+ *
+ * @param name the name of the SchemaMethod.
+ * @param value the SchemaMethod associated with "name".
+ */
+ public void addMethod(final String name, final SchemaMethod value)
+ {
+ value.setValue("_name", name);
+ _methods.add(value);
+ }
+
+ /**
+ * Add a new Method.
+ *
+ * @param value the SchemaMethod associated with "name".
+ */
+ public void addMethod(final SchemaMethod value)
+ {
+ _methods.add(value);
+ }
+
+ /**
+ * Set the value of the list of property names to use when constructing the object identifier.
+ * <p>
+ * When a QmfAgentData object is created the values of the properties specified here are used to
+ * create the associated ObjectId object name.
+ * @param idNames the list of property names to use when constructing the object identifier.
+ */
+ public void setIdNames(final String... idNames)
+ {
+ _idNames = idNames;
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ System.out.println("SchemaObjectClass:");
+ getClassId().listValues();
+
+ if (hasValue("_desc")) System.out.println("desc: " + getDesc());
+
+ if (getMethodCount() > 0)
+ {
+ System.out.println("methods:");
+ }
+ for (SchemaMethod m : _methods)
+ {
+ m.listValues();
+ }
+
+ if (getPropertyCount() > 0)
+ {
+ System.out.println("properties:");
+ }
+ for (SchemaProperty p : _properties)
+ {
+ p.listValues();
+ }
+ }
+
+ /**
+ * Return the underlying map.
+ * <p>
+ * We need to convert any methods from SchemaMethod to Map and any properties from SchemaProperty to Map
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ List<Map> mapEncodedMethods = new ArrayList<Map>();
+ for (SchemaMethod m : _methods)
+ {
+ mapEncodedMethods.add(m.mapEncode());
+ }
+ setValue("_methods", mapEncodedMethods);
+
+ List<Map> mapEncodedProperties = new ArrayList<Map>();
+ for (SchemaProperty p : _properties)
+ {
+ mapEncodedProperties.add(p.mapEncode());
+ }
+ setValue("_properties", mapEncodedProperties);
+
+ setValue("_schema_id", getClassId().mapEncode());
+
+ return super.mapEncode();
+ }
+
+ /**
+ * Generate the partial hash for the schema fields in this class.
+ * @param md5 the MessageDigest to be updated.
+ */
+ @Override
+ protected void updateHash(MessageDigest md5)
+ {
+ super.updateHash(md5);
+
+ for (SchemaMethod m : _methods)
+ {
+ m.updateHash(md5);
+ }
+
+ for (SchemaProperty p : _properties)
+ {
+ p.updateHash(md5);
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaProperty.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaProperty.java
new file mode 100644
index 0000000000..2aca9ef1d3
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/SchemaProperty.java
@@ -0,0 +1,364 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.util.Map;
+
+// Reuse this class as it provides a handy mechanism to parse an options String into a Map
+import org.apache.qpid.messaging.util.AddressParser;
+
+/**
+ * The SchemaProperty class describes a single data item in a QmfData object. A SchemaProperty is a list of
+ * named attributes and their values. QMF defines a set of primitive attributes. An application can extend
+ * this set of attributes with application-specific attributes.
+ * <p>
+ * QMF reserved attribute names all start with the underscore character ("_"). Do not create an application-specific
+ * attribute with a name starting with an underscore.
+ * <p>
+ * Once instantiated, the SchemaProperty is immutable.
+ * <p>
+ * Note that there appear to be some differences between the fields mentioned in
+ * <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API propsal</a> and
+ * <a href=https://cwiki.apache.org/qpid/qmf-map-message-protocol.html>QMF2 Map Message protocol</a>.
+ * I've gone with what's stated in the protocol documentation as this seems more accurate, at least for Qpid 0.10
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaProperty extends QmfData
+{
+ /**
+ * Construct a SchemaProperty from its Map representation.
+ */
+ public SchemaProperty(final Map m)
+ {
+ super(m);
+ }
+
+ /**
+ * Construct a SchemaProperty from its name and type.
+ *
+ * @param name the name of the SchemaProperty.
+ * @param type the QmfType of the SchemaProperty.
+ */
+ public SchemaProperty(final String name, final QmfType type) throws QmfException
+ {
+ this(name, type, null);
+ }
+
+ /**
+ * Construct a SchemaProperty from its name, type and options.
+ *
+ * @param name the name of the SchemaProperty.
+ * @param type the QmfType of the SchemaProperty.
+ * @param options a String containing the SchemaProperty options in the form:
+ * <pre>
+ * "{&lt;option1&gt;: &lt;value1&gt;, &lt;option2&gt;: &lt;value2&gt;}".
+ * </pre>
+ * Example:
+ * <pre>
+ * "{dir:IN, unit:metre, min:1, max:5, desc: 'ladder extension range'}"
+ * </pre>
+ */
+ public SchemaProperty(final String name, final QmfType type, final String options) throws QmfException
+ {
+ setValue("_name", name);
+ setValue("_type", type.toString());
+
+ if (options != null && options.length() != 0)
+ {
+ Map optMap = new AddressParser(options).map();
+
+ if (optMap.containsKey("index"))
+ {
+ String value = optMap.get("index").toString();
+ setValue("_index", Boolean.valueOf(value));
+ }
+
+ if (optMap.containsKey("access"))
+ {
+ String value = (String)optMap.get("access");
+ if (value.equals("RC") || value.equals("RO") || value.equals("RW"))
+ {
+ setValue("_access", value);
+ }
+ else
+ {
+ throw new QmfException("Invalid value for 'access' option. Expected RC, RO, or RW");
+ }
+ }
+
+ if (optMap.containsKey("unit"))
+ {
+ String value = (String)optMap.get("unit");
+ setValue("_unit", value);
+ }
+
+ if (optMap.containsKey("min"))
+ { // Slightly odd way of parsing, but AddressParser stores integers as Integer, which seems OK but it limits
+ // things like queue length to 2GB. I think this should change so this code deliberately avoids assuming
+ // integers are encoded as Integer by using the String representation instead.
+ long value = Long.parseLong(optMap.get("min").toString());
+ setValue("_min", value);
+ }
+
+ if (optMap.containsKey("max"))
+ { // Slightly odd way of parsing, but AddressParser stores integers as Integer. which seems OK but it limits
+ // things like queue length to 2GB. I think this should change so this code deliberately avoids assuming
+ // integers are encoded as Integer by using the String representation instead.
+ long value = Long.parseLong(optMap.get("max").toString());
+ setValue("_max", value);
+ }
+
+ if (optMap.containsKey("maxlen"))
+ { // Slightly odd way of parsing, but AddressParser stores integers as Integer, which seems OK but it limits
+ // things like queue length to 2GB. I think this should change so this code deliberately avoids assuming
+ // integers are encoded as Integer by using the String representation instead.
+ long value = Long.parseLong(optMap.get("maxlen").toString());
+ setValue("_maxlen", value);
+ }
+
+ if (optMap.containsKey("desc"))
+ {
+ String value = (String)optMap.get("desc");
+ setValue("_desc", value);
+ }
+
+ if (optMap.containsKey("dir"))
+ {
+ String value = (String)optMap.get("dir");
+ if (value.equals("IN"))
+ {
+ setValue("_dir", "I");
+ }
+ else if (value.equals("OUT"))
+ {
+ setValue("_dir", "O");
+ }
+ else if (value.equals("INOUT"))
+ {
+ setValue("_dir", "IO");
+ }
+ else
+ {
+ throw new QmfException("Invalid value for 'dir' option. Expected IN, OUT, or INOUT");
+ }
+ }
+
+ if (optMap.containsKey("subtype"))
+ {
+ String value = (String)optMap.get("subtype");
+ setValue("_subtype", value);
+ }
+ }
+ }
+
+ /**
+ * Return the property's name.
+ * @return the property's name.
+ */
+ public String getName()
+ {
+ return getStringValue("_name");
+ }
+
+ /**
+ * Return the property's QmfType.
+ * @return the property's QmfType.
+ */
+ public QmfType getType()
+ {
+ return QmfType.valueOf(getStringValue("_type"));
+ }
+
+ /**
+ * Return true iff this property is an index of an object.
+ * @return true iff this property is an index of an object. Default is false.
+ */
+ public boolean isIndex()
+ {
+ return hasValue("_index") ? getBooleanValue("_index") : false;
+ }
+
+ /**
+ * Return true iff this property is optional.
+ * @return true iff this property is optional. Default is false.
+ */
+ public boolean isOptional()
+ {
+ return hasValue("_optional") ? getBooleanValue("_optional") : false;
+ }
+
+ /**
+ * Return the property's remote access rules.
+ * @return the property's remote access rules "RC"=read/create, "RW"=read/write, "RO"=read only (default).
+ */
+ public String getAccess()
+ {
+ return getStringValue("_access");
+ }
+
+ /**
+ * Return an annotation string describing units of measure for numeric values (optional).
+ * @return an annotation string describing units of measure for numeric values (optional).
+ */
+ public String getUnit()
+ {
+ return getStringValue("_unit");
+ }
+
+ /**
+ * Return minimum value (optional).
+ * @return minimum value (optional).
+ */
+ public long getMin()
+ {
+ return getLongValue("_min");
+ }
+
+ /**
+ * Return maximum value (optional).
+ * @return maximum value (optional).
+ */
+ public long getMax()
+ {
+ return getLongValue("_max");
+ }
+
+ /**
+ * Return maximum length for string values (optional).
+ * @return maximum length for string values (optional).
+ */
+ public long getMaxLen()
+ {
+ return getLongValue("_maxlen");
+ }
+
+ /**
+ * Return optional string description of this Property.
+ * @return optional string description of this Property.
+ */
+ public String getDesc()
+ {
+ return getStringValue("_desc");
+ }
+
+ /**
+ * Return the direction of information travel.
+ * @return "I"=input, "O"=output, or "IO"=input/output (required for method arguments, otherwise optional).
+ */
+ public String getDirection()
+ {
+ return getStringValue("_dir");
+ }
+
+ /**
+ * Return string indicating the formal application type.
+ * @return string indicating the formal application type for the data, example: "URL", "Telephone number", etc.
+ */
+ public String getSubtype()
+ {
+ return getStringValue("_subtype");
+ }
+
+ /**
+ * Return a SchemaClassId. If the type is a reference to another managed object.
+ * @return a SchemaClassId. If the type is a reference to another managed object, this field may be used.
+ to specify the required class for that object
+ */
+ public SchemaClassId getReference()
+ {
+ return new SchemaClassId((Map)getValue("_references"));
+ }
+
+ /**
+ * Return the value of the attribute named "name".
+ * @return the value of the attribute named "name".
+ * <p>
+ * This method can be used to retrieve application-specific attributes. "name" should start with the prefix "x-".
+ */
+ public String getAttribute(final String name)
+ {
+ return getStringValue(name);
+ }
+
+ /**
+ * Generate the partial hash for the schema fields in this class.
+ * @param md5 the MessageDigest to be updated
+ */
+ protected void updateHash(MessageDigest md5)
+ {
+ try
+ {
+ md5.update(getName().getBytes("UTF-8"));
+ md5.update(getType().toString().getBytes("UTF-8"));
+ md5.update(getSubtype().getBytes("UTF-8"));
+ md5.update(getAccess().getBytes("UTF-8"));
+ if (isIndex())
+ {
+ md5.update((byte)1);
+ }
+ else
+ {
+ md5.update((byte)0);
+ }
+ if (isOptional())
+ {
+ md5.update((byte)1);
+ }
+ else
+ {
+ md5.update((byte)0);
+ }
+ md5.update(getUnit().getBytes("UTF-8"));
+ md5.update(getDesc().getBytes("UTF-8"));
+ md5.update(getDirection().getBytes("UTF-8"));
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ }
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ System.out.println("SchemaProperty:");
+ System.out.println("_name: " + getName());
+ System.out.println("_type: " + getType());
+ if (hasValue("_index")) System.out.println("is index: " + isIndex());
+ if (hasValue("_optional")) System.out.println("is optional: " + isOptional());
+ if (hasValue("_access")) System.out.println("access: " + getAccess());
+ if (hasValue("_unit")) System.out.println("unit: " + getUnit());
+ if (hasValue("_min")) System.out.println("min: " + getMin());
+ if (hasValue("_max")) System.out.println("max: " + getMax());
+ if (hasValue("_max_len")) System.out.println("maxlen: " + getMaxLen());
+ if (hasValue("_desc")) System.out.println("desc: " + getDesc());
+ if (hasValue("_dir")) System.out.println("dir: " + getDirection());
+ if (hasValue("_subtype")) System.out.println("subtype: " + getSubtype());
+ if (hasValue("_references")) System.out.println("reference: " + getReference());
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkItem.java
new file mode 100644
index 0000000000..750c4a2e45
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkItem.java
@@ -0,0 +1,399 @@
+/*
+ *
+ * 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.qmf2.common;
+
+import java.util.HashMap;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.console.Agent;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <p>
+ * A WorkItem describes an event that has arrived for the application to process.
+ * <p>
+ * The Notifier is invoked when one or more WorkItems become available for processing.
+ * <p>
+ * The type of the Object returned by getParams is determined by the WorkItemType and described below.
+ * <p>
+ *
+ * <table width="100%" border="1"><thead><tr><th>WorkItem Type</th><th>Description</th></tr></thead><tbody>
+ *
+ *
+ * <tr>
+ * <td>AGENT_ADDED:</td>
+ * <td>
+ * When the QMF Console receives the first heartbeat from an Agent, an AGENT_ADDED WorkItem is pushed onto the
+ * work-queue.
+ * <p>
+ * The getParams() method returns a map which contains a reference to the new Console Agent instance. The reference is
+ * indexed from the map using the key string "agent". There is no handle associated with this WorkItem.
+ * <p>
+ * Note: If a new Agent is discovered as a result of the Console findAgent() method, then no AGENT_ADDED WorkItem is
+ * generated for that Agent.
+ * <p>
+ * Use AgentAddedWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>AGENT_DELETED:</td>
+ * <td>
+ * When a known Agent stops sending heartbeat messages the Console will time out that Agent. On Agent timeout, an
+ * AGENT_DELETED WorkItem is pushed onto the work-queue.
+ * <p>
+ * The getParams() method returns a map which contains a reference to the Agent instance that has been deleted.
+ * The reference is indexed from the map using the key string "agent". There is no handle associated with this WorkItem.
+ * <p>
+ * The Console application must release all saved references to the Agent before returning the WorkItem.
+ * <p>
+ * Use AgentDeletedWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>AGENT_RESTARTED:</td>
+ * <td>
+ * Sent when the QMF Console detects an Agent was restarted, an AGENT_RESTARTED WorkItem is pushed onto the work-queue.
+ * <p>
+ * The getParams() method returns a map which contains a reference to the Console Agent instance. The reference
+ * is indexed from the map using the key string "agent". There is no handle associated with this WorkItem.
+ * <p>
+ * Use AgentRestartedWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>AGENT_HEARTBEAT:</td>
+ * <td>
+ * When the QMF Console receives heartbeats from an Agent, an AGENT_HEARTBEAT WorkItem is pushed onto the work-queue.
+ * <p>
+ * The getParams() method returns a map which contains a reference to the Console Agent instance. The reference
+ * is indexed from the map using the key string "agent". There is no handle associated with this WorkItem.
+ * <p>
+ * Note: the first heartbeat results in an AGENT_ADDED WorkItem for Agent not an AGENT_HEARTBEAT.
+ * <p>
+ * Use AgentHeartbeatWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>NEW_PACKAGE:</td><td>TBD</td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>NEW_CLASS:</td><td>TBD</td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>OBJECT_UPDATE:</td>
+ * <td>
+ * The OBJECT_UPDATE WorkItem is generated in response to an asynchronous refresh made by a QmfConsoleData object.
+ * <p>
+ * The getParams() method will return a QmfConsoleData.
+ * <p>
+ * The getHandle() method returns the reply handle provided to the refresh() method call.
+ * This handle is merely the handle used for the asynchronous response, it is not associated with the QmfConsoleData
+ * in any other way.
+ * <p>
+ * Use ObjectUpdateWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>METHOD_RESPONSE:</td>
+ * <td>
+ * The METHOD_RESPONSE WorkItem is generated in response to an asynchronous invokeMethod made by a QmfConsoleData object.
+ * <p>
+ * The getParams() method will return a MethodResult object.
+ * <p>
+ * The getHandle() method returns the reply handle provided to the refresh() method call.
+ * This handle is merely the handle used for the asynchronous response, it is not associated with the QmfConsoleData
+ * in any other way.
+ * <p>
+ * Use MethodResponseWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>EVENT_RECEIVED:</td>
+ * <td>
+ * When an Agent generates a QmfEvent an EVENT_RECEIVED WorkItem is pushed onto the work-queue.
+ * <p>
+ * The getParams() method returns a map which contains a reference to the Console Agent instance that generated
+ * the Event and a reference to the QmfEvent itself. The Agent reference is indexed from the map using the key string
+ * "agent, The QmfEvent reference is indexed from the map using the key string "event". There is no handle associated
+ * with this WorkItem.
+ * <p>
+ * Use EventReceivedWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>SUBSCRIBE_RESPONSE:</td>
+ * <td>
+ * The SUBSCRIBE_RESPONSE WorkItem returns the result of a subscription request made by this Console. This WorkItem is
+ * generated when the Console's createSubscription() is called in an asychronous manner, rather than pending for the result.
+ * <p>
+ * The getParams() method will return an instance of the SubscribeParams class.
+ * <p>
+ * The SubscriptionId object must be used when the subscription is refreshed or cancelled. It must be passed to the
+ * Console's refresh_subscription() and cancelSubscription() methods. The value of the SubscriptionId does not change
+ * over the lifetime of the subscription.
+ * <p>
+ * The console handle will be provided by the Agent on each data indication event that corresponds to this subscription.
+ * It should not change for the lifetime of the subscription.
+ * <p>
+ * The getHandle() method returns the reply handle provided to the createSubscription() method call. This handle is
+ * merely the handle used for the asynchronous response, it is not associated with the subscription in any other way.
+ * <p>
+ * Once a subscription is created, the Agent that maintains the subscription will periodically issue updates for the
+ * subscribed data. This update will contain the current values of the subscribed data, and will appear as the first
+ * SUBSCRIPTION_INDICATION WorkItem for this subscription.
+ * <p>
+ * Use SubscribeResponseWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>SUBSCRIPTION_INDICATION:</td>
+ * <td>
+ * The SUBSCRIPTION_INDICATION WorkItem signals the arrival of an update to subscribed data from the Agent.
+ * <p>
+ * The getParams() method will return an instance of the SubscribeIndication class.
+ * The getHandle() method returns null.
+ * <p>
+ * Use SubscriptionIndicationWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>RESUBSCRIBE_RESPONSE:</td>
+ * <td>
+ * The RESUBSCRIBE_RESPONSE WorkItem is generated in response to a subscription refresh request made by this Console.
+ * This WorkItem is generated when the Console's refreshSubscription() is called in an asychronous manner, rather than
+ * pending for the result.
+ * <p>
+ * The getParams() method will return an instance of the SubscribeParams class.
+ * <p>
+ * The getHandle() method returns the reply handle provided to the refreshSubscription() method call. This handle is
+ * merely the handle used for the asynchronous response, it is not associated with the subscription in any other way.
+ * <p>
+ * Use ResubscribeResponseWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>METHOD_CALL:</td>
+ * <td>
+ * The METHOD_CALL WorkItem describes a method call that must be serviced by the application on behalf of this Agent.
+ * <p>
+ * The getParams() method will return an instance of the MethodCallParams class.
+ * <p>
+ * Use MethodCallWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>QUERY:</td>
+ * <td>
+ * The QUERY WorkItem describes a query that the application must service. The application should call the
+ * queryResponse() method for each object that satisfies the query. When complete, the application must call the
+ * queryComplete() method. If a failure occurs, the application should indicate the error to the agent by calling
+ * the query_complete() method with a description of the error.
+ * <p>
+ * The getParams() method will return an instance of the QmfQuery class.
+ * <p>
+ * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's queryResponse()
+ * and queryComplete() methods.
+ * <p>
+ * Use QueryWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>SUBSCRIBE_REQUEST:</td>
+ * <td>
+ * The SUBSCRIBE_REQUEST WorkItem provides a query that the agent application must periodically publish until the
+ * subscription is cancelled or expires. On receipt of this WorkItem, the application should call the Agent
+ * subscriptionResponse() method to acknowledge the request. On each publish interval, the application should call Agent
+ * subscriptionIndicate(), passing a list of the objects that satisfy the query. The subscription remains in effect until
+ * an UNSUBSCRIBE_REQUEST WorkItem for the subscription is received, or the subscription expires.
+ * <p>
+ * The getParams() method will return an instance of the SubscriptionParams class.
+ * <p>
+ * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's
+ * subscriptionResponse() method.
+ * <p>
+ * Use SubscribeRequestWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>RESUBSCRIBE_REQUEST:</td>
+ * <td>
+ * The RESUBSCRIBE_REQUEST is sent by a Console to renew an existing subscription. The Console may request a new
+ * duration for the subscription, otherwise the previous lifetime interval is repeated.
+ * <p>
+ * The getParams() method will return an instance of the ResubscribeParams class.
+ * <p>
+ * The getHandle() WorkItem method returns the reply handle which should be passed to the Agent's
+ * subscriptionResponse() method.
+ * <p>
+ * Use ResubscribeRequestWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ *
+ *
+ * <tr>
+ * <td>UNSUBSCRIBE_REQUEST:</td>
+ * <td>
+ * The UNSUBSCRIBE_REQUEST is sent by a Console to terminate an existing subscription. The Agent application should
+ * terminate the given subscription if it exists, and cancel sending any further updates against it.
+ * <p>
+ * The getParams() method will return a String holding the subscriptionId.
+ * <p>
+ * The getHandle() method returns null.
+ * <p>
+ * Use UnsubscribeRequestWorkItem to enable neater access.
+ * </td>
+ * </tr>
+ * </table>
+ * <p>
+ * The following diagram illustrates the QMF2 WorkItem class hierarchy.
+ * <p>
+ * <img src="doc-files/WorkItem.png"/>
+ * @author Fraser Adams
+ */
+
+public class WorkItem
+{
+ /**
+ * An Enumeration of the types of WorkItems produced on the Console or Agent.
+ */
+ public enum WorkItemType
+ {
+ // Enumeration of the types of WorkItems produced on the Console
+ AGENT_ADDED,
+ AGENT_DELETED,
+ AGENT_RESTARTED,
+ AGENT_HEARTBEAT,
+ NEW_PACKAGE,
+ NEW_CLASS,
+ OBJECT_UPDATE,
+ EVENT_RECEIVED,
+ METHOD_RESPONSE,
+ SUBSCRIBE_RESPONSE,
+ SUBSCRIPTION_INDICATION,
+ RESUBSCRIBE_RESPONSE,
+ // Enumeration of the types of WorkItems produced on the Agent
+ METHOD_CALL,
+ QUERY,
+ SUBSCRIBE_REQUEST,
+ RESUBSCRIBE_REQUEST,
+ UNSUBSCRIBE_REQUEST;
+ }
+
+ private final WorkItemType _type;
+ private final Handle _handle;
+ private final Object _params;
+
+ /**
+ * Construct a WorkItem
+ *
+ * @param type the type of WorkItem specified by the WorkItemType enum
+ * @param handle the handle passed by async calls - the correlation ID
+ * @param params the payload of the WorkItem
+ */
+ public WorkItem(WorkItemType type, Handle handle, Object params)
+ {
+ _type = type;
+ _handle = handle;
+ _params = params;
+ }
+
+ /**
+ * Return the type of work item.
+ * @return the type of work item.
+ */
+ public final WorkItemType getType()
+ {
+ return _type;
+ }
+
+ /**
+ * Return the reply handle for an asynchronous operation, if present.
+ * @return the reply handle for an asynchronous operation, if present.
+ */
+ public final Handle getHandle()
+ {
+ return _handle;
+ }
+
+ /**
+ * Return the payload of the work item.
+ * @return the payload of the work item.
+ * <p>
+ * The type of this object is determined by the type of the workitem as follows:
+ * <pre>
+ * <b>Console</b>
+ * AGENT_ADDED: Map{"agent":Agent} - Use AgentAddedWorkItem to enable neater access
+ * AGENT_DELETED: Map{"agent":Agent} - Use AgentDeletedWorkItem to enable neater access
+ * AGENT_RESTARTED: Map{"agent":Agent} - Use AgentRestartedWorkItem to enable neater access
+ * AGENT_HEARTBEAT: Map{"agent":Agent} - Use AgentHeartbeatWorkItem to enable neater access
+ * OBJECT_UPDATE: QmfConsoleData - Use ObjectUpdateWorkItem to enable neater access
+ * METHOD_RESPONSE: MethodResult - Use MethodResponseWorkItem to enable neater access
+ * EVENT_RECEIVED: Map{"agent":Agent, "event":QmfEvent} - Use EventReceivedWorkItem to enable neater access
+ * SUBSCRIBE_RESPONSE: SubscribeParams - Use SubscribeResponseWorkItem to enable neater access
+ * SUBSCRIPTION_INDICATION: SubscribeIndication - Use SubscriptionIndicationWorkItem to enable neater access
+ * RESUBSCRIBE_RESPONSE: SubscribeParams - Use ResubscribeResponseWorkItem to enable neater access
+ *
+ * <b>Agent</b>
+ * METHOD_CALL: MethodCallParams - Use MethodCallWorkItem to enable neater access
+ * QUERY: QmfQuery - Use QueryWorkItem to enable neater access
+ * SUBSCRIBE_REQUEST: SubscriptionParams - Use SubscribeRequestWorkItem to enable neater access
+ * RESUBSCRIBE_REQUEST: ResubscribeParams - Use ResubscribeRequestWorkItem to enable neater access
+ * UNSUBSCRIBE_REQUEST: String (subscriptionId) - Use UnsubscribeRequestWorkItem to enable neater access
+ * </pre>
+ */
+ @SuppressWarnings("unchecked")
+ public final <T> T getParams()
+ {
+ return (T)_params;
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkQueue.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkQueue.java
new file mode 100644
index 0000000000..75b4e5d855
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/WorkQueue.java
@@ -0,0 +1,106 @@
+/*
+ *
+ * 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.qmf2.common;
+
+// Misc Imports
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * This is an implementation of a QMF2 WorkQueue. In practice this is likely to be used by an Agent or Console.
+ *
+ * @author Fraser Adams
+ */
+public class WorkQueue
+{
+ /**
+ * Used to implement a thread safe queue of WorkItem objects
+ */
+ private BlockingQueue<WorkItem> _workQueue = new LinkedBlockingQueue<WorkItem>();
+
+ /**
+ * Return the count of pending WorkItems that can be retrieved.
+ * @return the count of pending WorkItems that can be retrieved.
+ */
+ public int size()
+ {
+ return _workQueue.size();
+ }
+
+ /**
+ * Obtains the next pending work item - blocking version
+ *
+ * @return the next pending work item, or null if none available.
+ */
+ public WorkItem getNextWorkitem()
+ {
+ try
+ {
+ return _workQueue.take();
+ }
+ catch (InterruptedException ie)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Obtains the next pending work item - balking version
+ *
+ * @param timeout the timeout in seconds. If timeout = 0 it returns immediately with either a WorkItem or null
+ * @return the next pending work item, or null if none available.
+ */
+ public WorkItem getNextWorkitem(long timeout)
+ {
+ try
+ {
+ return _workQueue.poll(timeout, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException ie)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Adds a WorkItem to the WorkQueue.
+ *
+ * @param item the WorkItem passed to the WorkQueue
+ */
+ public void addWorkItem(WorkItem item)
+ {
+ // We wrap the blocking put() method in a loop "just in case" InterruptedException occurs
+ // if it does we retry the put otherwise we carry on, notify then exit.
+ while (true)
+ {
+ try
+ {
+ _workQueue.put(item);
+ break;
+ }
+ catch (InterruptedException ie)
+ {
+ continue;
+ }
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Console.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Console.png
new file mode 100644
index 0000000000..cb2a5ee800
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Console.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfData.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfData.png
new file mode 100644
index 0000000000..2665803e39
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfData.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfEventListenerModel.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfEventListenerModel.png
new file mode 100644
index 0000000000..26a5f71b56
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfEventListenerModel.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfQuery.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfQuery.png
new file mode 100644
index 0000000000..9e471a08c0
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/QmfQuery.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Schema.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Schema.png
new file mode 100644
index 0000000000..b0277f4fc5
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Schema.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Subscriptions.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Subscriptions.png
new file mode 100644
index 0000000000..977e222129
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/Subscriptions.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkItem.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkItem.png
new file mode 100644
index 0000000000..14c8c56d28
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkItem.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkQueueEventModel.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkQueueEventModel.png
new file mode 100644
index 0000000000..fc2a722985
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/common/doc-files/WorkQueueEventModel.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Agent.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Agent.java
new file mode 100644
index 0000000000..8fa2ae8f1f
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Agent.java
@@ -0,0 +1,482 @@
+/*
+ *
+ * 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.qmf2.console;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.SchemaClass;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+
+/**
+ * Local representation (proxy) of a remote Agent.
+ * <p>
+ * This class holds some state that relates to the Agent and in addition some methods may be called on the agent.
+ * destroy(), invokeMethod() and refresh() are actually called by a proxy class AgentProxy. AgentProxy is actually
+ * an interface that is implemented by Console (as that's where all the JMS stuff is), we use this approach to
+ * avoid introducing a circular dependency between Agent and Console.
+ * <p>
+ * The Console application maintains a list of all known remote Agents.
+ * Each Agent is represented by an instance of the Agent class:
+ * <p>
+ * The following diagram illustrates the interactions between the Console, AgentProxy and the client side Agent
+ * representation.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ * @author Fraser Adams
+ */
+public final class Agent extends QmfData
+{
+ private AgentProxy _proxy;
+ private List<String> _packages = new ArrayList<String>();
+ private Map<SchemaClassId, SchemaClass> _schemaCache = new ConcurrentHashMap<SchemaClassId, SchemaClass>();
+ private long _epoch;
+ private long _heartbeatInterval;
+ private long _timestamp;
+ private boolean _eventsEnabled = true;
+ private boolean _isActive = true;
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+ *
+ * @param m the map used to construct the SchemaClass
+ * @param p the AgentProxy instance that implements some of the concrete behaviour of the local Agent representation.
+ */
+ public Agent(final Map m, final AgentProxy p)
+ {
+ super(m);
+ // Populate attributes translating any old style keys if necessary.
+ _epoch = hasValue("_epoch") ? getLongValue("_epoch") : getLongValue("epoch");
+ _heartbeatInterval = hasValue("_heartbeat_interval") ? getLongValue("_heartbeat_interval") :
+ getLongValue("heartbeat_interval");
+ _timestamp = hasValue("_timestamp") ? getLongValue("_timestamp") : getLongValue("timestamp");
+ _proxy = p;
+ }
+
+ /**
+ * Sets the state of the Agent, used as an assignment operator.
+ *
+ * @param m the Map used to initialise the Agent.
+ */
+ @SuppressWarnings("unchecked")
+ public void initialise(final Map m)
+ {
+ Map<String, Object> values = (Map<String, Object>)m.get("_values");
+ _values = (values == null) ? m : values;
+
+ // Populate attributes translating any old style keys if necessary.
+ _epoch = hasValue("_epoch") ? getLongValue("_epoch") : getLongValue("epoch");
+ _heartbeatInterval = hasValue("_heartbeat_interval") ? getLongValue("_heartbeat_interval") :
+ getLongValue("heartbeat_interval");
+ _timestamp = hasValue("_timestamp") ? getLongValue("_timestamp") : getLongValue("timestamp");
+ }
+
+ /**
+ * Return whether or not events are enabled for this Agent.
+ * @return a boolean indication of whether or not events are enabled for this Agent.
+ */
+ public boolean eventsEnabled()
+ {
+ return _eventsEnabled;
+ }
+
+ /**
+ * Deactivated this Agent. Called by the Console when the Agent times out.
+ */
+ public void deactivate()
+ {
+ _isActive = false;
+ }
+
+ /**
+ * Return the Agent instance name.
+ * @return the Agent instance name.
+ */
+ public String getInstance()
+ {
+ return getStringValue("_instance");
+ }
+
+ /**
+ * Return the identifying name string of the Agent.
+ * @return the identifying name string of the Agent. This name is used to send AMQP messages directly to this agent.
+ */
+ public String getName()
+ {
+ return getStringValue("_name");
+ }
+
+ /**
+ * Return the product name string of the Agent.
+ * @return the product name string of the Agent.
+ */
+ public String getProduct()
+ {
+ return getStringValue("_product");
+ }
+
+ /**
+ * Return the Agent vendor name.
+ * @return the Agent vendor name.
+ */
+ public String getVendor()
+ {
+ return getStringValue("_vendor");
+ }
+
+ /**
+ * Return the Epoch stamp.
+ * @return the Epoch stamp, used to determine if an Agent has been restarted.
+ */
+ public long getEpoch()
+ {
+ return _epoch;
+ }
+
+ /**
+ * Set the Epoch stamp.
+ * @param epoch the new Epoch stamp, used to indicate that an Agent has been restarted.
+ */
+ public void setEpoch(long epoch)
+ {
+ _epoch = epoch;
+ }
+
+ /**
+ * Return the time that the Agent waits between sending hearbeat messages.
+ * @return the time that the Agent waits between sending hearbeat messages.
+ */
+ public long getHeartbeatInterval()
+ {
+ return _heartbeatInterval;
+ }
+
+ /**
+ * Return the timestamp of the Agent's last update.
+ * @return the timestamp of the Agent's last update.
+ */
+ public long getTimestamp()
+ {
+ return _timestamp;
+ }
+
+ /**
+ * Return true if the agent is alive.
+ * @return true if the agent is alive (heartbeats have not timed out).
+ */
+ public boolean isActive()
+ {
+ return _isActive;
+ }
+
+ /**
+ * Request that the Agent updates the value of this object's contents.
+ *
+ * @param objectId the ObjectId being queried for..
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses.
+ * @param timeout the maximum time to wait for a response, overrides default replyTimeout.
+ * @return the refreshed object.
+ */
+ public QmfConsoleData refresh(final ObjectId objectId, final String replyHandle, final int timeout) throws QmfException
+ {
+ if (isActive())
+ {
+ return _proxy.refresh(this, objectId, replyHandle, timeout);
+ }
+ else
+ {
+ throw new QmfException("Agent.refresh() called from deactivated Agent");
+ }
+ }
+
+ /**
+ * Helper method to create a Map containing a QMF method request.
+ *
+ * @param objectId the objectId of the remote object.
+ * @param name the remote method name.
+ * @param inArgs the formal parameters of the remote method name.
+ * @return a Map containing a QMF method request.
+ */
+ private Map<String, Object> createRequest(final ObjectId objectId, final String name, final QmfData inArgs)
+ {
+ // Default sizes for HashMap should be fine for request
+ Map<String, Object> request = new HashMap<String, Object>();
+ if (objectId != null)
+ {
+ request.put("_object_id", objectId.mapEncode());
+ }
+ request.put("_method_name", name);
+ if (inArgs != null)
+ {
+ request.put("_arguments", inArgs.mapEncode());
+ if (inArgs.getSubtypes() != null)
+ {
+ request.put("_subtypes", inArgs.getSubtypes());
+ }
+ }
+ return request;
+ }
+
+ /**
+ * Sends a method request to the Agent. Delegates to the AgentProxy to actually send the method as it's the
+ * AgentProxy that knows about connections, sessions and messages.
+ *
+ * @param objectId the objectId of the remote object.
+ * @param name the remote method name.
+ * @param inArgs the formal parameters of the remote method name.
+ * @param timeout the maximum time to wait for a response, overrides default replyTimeout.
+ * @return the MethodResult.
+ */
+ protected MethodResult invokeMethod(final ObjectId objectId, final String name,
+ final QmfData inArgs, final int timeout) throws QmfException
+ {
+ if (isActive())
+ {
+ return _proxy.invokeMethod(this, createRequest(objectId, name, inArgs), null, timeout);
+ }
+ else
+ {
+ throw new QmfException("Agent.invokeMethod() called from deactivated Agent");
+ }
+ }
+
+ /**
+ * Sends an asynchronous method request to the Agent. Delegates to the AgentProxy to actually send the method as
+ * it's the AgentProxy that knows about connections, sessions and messages.
+ *
+ * @param objectId the objectId of the remote object.
+ * @param name the remote method name.
+ * @param inArgs the formal parameters of the remote method name.
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses.
+ */
+ protected void invokeMethod(final ObjectId objectId, final String name,
+ final QmfData inArgs, final String replyHandle) throws QmfException
+ {
+ if (isActive())
+ {
+ _proxy.invokeMethod(this, createRequest(objectId, name, inArgs), replyHandle, -1);
+ }
+ else
+ {
+ throw new QmfException("Agent.invokeMethod() called from deactivated Agent");
+ }
+ }
+
+ /**
+ * Sends a method request to the Agent. Delegates to the AgentProxy to actually send the method as it's the
+ * AgentProxy that knows about connections, sessions and messages.
+ *
+ * @param name the remote method name.
+ * @param inArgs the formal parameters of the remote method name.
+ * @return the MethodResult.
+ */
+ public MethodResult invokeMethod(final String name, final QmfData inArgs) throws QmfException
+ {
+ return invokeMethod(null, name, inArgs, -1);
+ }
+
+ /**
+ * Sends a method request to the Agent. Delegates to the AgentProxy to actually send the method as it's the
+ * AgentProxy that knows about connections, sessions and messages.
+ *
+ * @param name the remote method name.
+ * @param inArgs the formal parameters of the remote method name.
+ * @param timeout the maximum time to wait for a response, overrides default replyTimeout.
+ * @return the MethodResult.
+ */
+ public MethodResult invokeMethod(final String name, final QmfData inArgs, final int timeout) throws QmfException
+ {
+ return invokeMethod(null, name, inArgs, timeout);
+ }
+
+ /**
+ * Sends a method request to the Agent. Delegates to the AgentProxy to actually send the method as it's the
+ * AgentProxy that knows about connections, sessions and messages.
+ *
+ * @param name the remote method name.
+ * @param inArgs the formal parameters of the remote method name.
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses.
+ */
+ public void invokeMethod(final String name, final QmfData inArgs, final String replyHandle) throws QmfException
+ {
+ invokeMethod(null, name, inArgs, replyHandle);
+ }
+
+ /**
+ * Remove a Subscription. Delegates to the AgentProxy to actually remove the Subscription as it's the AgentProxy
+ * that really knows about subscriptions.
+ *
+ * @param subscription the SubscriptionManager that we wish to remove.
+ */
+ public void removeSubscription(final SubscriptionManager subscription)
+ {
+ _proxy.removeSubscription(subscription);
+ }
+
+ /**
+ * Allows reception of events from this agent.
+ */
+ public void enableEvents()
+ {
+ _eventsEnabled = true;
+ }
+
+ /**
+ * Prevents reception of events from this agent.
+ */
+ public void disableEvents()
+ {
+ _eventsEnabled = false;
+ }
+
+ /**
+ * Releases this Agent instance. Once called, the Console application should not reference this instance again.
+ */
+ public void destroy()
+ {
+ _timestamp = 0;
+ _proxy.destroy(this);
+ }
+
+ /**
+ * Clears the internally cached schema. Generally done when we wich to refresh the schema information from the
+ * remote Agent.
+ */
+ public void clearSchemaCache()
+ {
+ _schemaCache.clear();
+ _packages.clear();
+ }
+
+ /**
+ * Stores the schema and package information obtained by querying the remote Agent.
+ *
+ * @param classes the list of SchemaClassIds obtained by querying the remote Agent.
+ */
+ public void setClasses(final List<SchemaClassId> classes)
+ {
+ if (classes == null)
+ {
+ clearSchemaCache();
+ return;
+ }
+
+ for (SchemaClassId classId : classes)
+ {
+ _schemaCache.put(classId, SchemaClass.EMPTY_SCHEMA);
+ if (!_packages.contains(classId.getPackageName()))
+ {
+ _packages.add(classId.getPackageName());
+ }
+ }
+ }
+
+ /**
+ * Return the list of SchemaClassIds associated with this Agent.
+ * @return the list of SchemaClassIds associated with this Agent.
+ */
+ public List<SchemaClassId> getClasses()
+ {
+ if (_schemaCache.size() == 0)
+ {
+ return Collections.emptyList();
+ }
+ return new ArrayList<SchemaClassId>(_schemaCache.keySet());
+ }
+
+ /**
+ * Return the list of packages associated with this Agent.
+ * @return the list of packages associated with this Agent.
+ */
+ public List<String> getPackages()
+ {
+ return _packages;
+ }
+
+ /**
+ * Return the SchemaClass associated with this Agent.
+ * @return the list of SchemaClass associated with this Agent.
+ * <p>
+ * I <i>believe</i> that there should only be one entry in the list returned when looking up a specific chema by classId.
+ */
+ public List<SchemaClass> getSchema(final SchemaClassId classId)
+ {
+ SchemaClass schema = _schemaCache.get(classId);
+ if (schema == SchemaClass.EMPTY_SCHEMA)
+ {
+ return Collections.emptyList();
+ }
+
+ List<SchemaClass> results = new ArrayList<SchemaClass>();
+ results.add(schema);
+ return results;
+ }
+
+ /**
+ * Set a schema keyed by SchemaClassId.
+ *
+ * @param classId the SchemaClassId indexing the particular schema.
+ * @param schemaList the schema being indexed.
+ * <p>
+ * I <i>believe</i> that there should only be one entry in the list returned when looking up a specific chema by classId.
+ */
+ public void setSchema(final SchemaClassId classId, final List<SchemaClass> schemaList)
+ {
+ if (schemaList == null || schemaList.size() == 0)
+ {
+ _schemaCache.put(classId, SchemaClass.EMPTY_SCHEMA);
+ }
+ else
+ {
+ // I believe that there should only be one entry in the list returned when looking up
+ // a specific chema by classId
+ _schemaCache.put(classId, schemaList.get(0));
+ }
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ super.listValues();
+ System.out.println("Agent:");
+ System.out.println("instance: " + getInstance());
+ System.out.println("name: " + getName());
+ System.out.println("product: " + getProduct());
+ System.out.println("vendor: " + getVendor());
+ System.out.println("epoch: " + getEpoch());
+ System.out.println("heartbeatInterval: " + getHeartbeatInterval());
+ System.out.println("timestamp: " + new Date(getTimestamp()/1000000l));
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAccessWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAccessWorkItem.java
new file mode 100644
index 0000000000..ff5668fe2e
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAccessWorkItem.java
@@ -0,0 +1,80 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.HashMap;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Abstract class that acts as a superclass for all WorkItems that need to set and retrieve an Agent.
+ * <p>
+ * This class is a convenience class to enable neater access the the WorkItem params for this type of WorkItem.
+ *
+ * @author Fraser Adams
+ */
+
+public abstract class AgentAccessWorkItem extends WorkItem
+{
+ /**
+ * Helper method to create the WorkItem params as a Map.
+ *
+ * @param agent the Agent associated with the WorkItem.
+ * @param event the QmfEvent associated with the WorkItem.
+ */
+ protected static Map<String, Object> newParams(final Agent agent, final QmfEvent event)
+ {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("agent", agent);
+ if (event != null)
+ {
+ params.put("event", event);
+ }
+ return params;
+ }
+
+ /**
+ * Construct an AgentAccessWorkItem. Convenience constructor not in API
+ *
+ * @param type the type of WorkItem specified by the WorkItemType enum
+ * @param handle the handle passed by async calls - the correlation ID
+ * @param params the payload of the WorkItem
+ */
+ public AgentAccessWorkItem(final WorkItemType type, final Handle handle, final Object params)
+ {
+ super(type, handle, params);
+ }
+
+ /**
+ * Return the Agent stored in the params Map.
+ * @return the Agent stored in the params Map.
+ */
+ public final Agent getAgent()
+ {
+ Map<String, Object> p = this.<Map<String, Object>>getParams();
+ return (Agent)p.get("agent");
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAddedWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAddedWorkItem.java
new file mode 100644
index 0000000000..0470b34e58
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentAddedWorkItem.java
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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.qmf2.console;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * AGENT_ADDED: When the QMF Console receives the first heartbeat from an Agent, an AGENT_ADDED WorkItem
+ * is pushed onto the work-queue. The WorkItem's getParam() call returns a map which contains
+ * a reference to the new Console Agent instance. The reference is indexed from the map using
+ * the key string "agent". There is no handle associated with this WorkItem.
+ *
+ * Note: If a new Agent is discovered as a result of the Console findAgent() method, then no
+ * AGENT_ADDED WorkItem is generated for that Agent.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class AgentAddedWorkItem extends AgentAccessWorkItem
+{
+ /**
+ * Construct an AgentAddedWorkItem. Convenience constructor not in API
+ *
+ * @param agent the Agent used to populate the WorkItem's param
+ */
+ public AgentAddedWorkItem(final Agent agent)
+ {
+ super(WorkItemType.AGENT_ADDED, null, newParams(agent, null));
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentDeletedWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentDeletedWorkItem.java
new file mode 100644
index 0000000000..ef31b8105a
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentDeletedWorkItem.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * 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.qmf2.console;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * AGENT_DELETED: When a known Agent stops sending heartbeat messages, the Console will time out that Agent.
+ * On Agent timeout, an AGENT_DELETED WorkItem is pushed onto the work-queue. The WorkItem's
+ * getParam() call returns a map which contains a reference to the Agent instance that has
+ * been deleted. The reference is indexed from the map using the key string "agent". There is
+ * no handle associated with this WorkItem.
+ *
+ * The Console application must release all saved references to the Agent before returning the
+ * WorkItem.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class AgentDeletedWorkItem extends AgentAccessWorkItem
+{
+ /**
+ * Construct an AgentDeletedWorkItem. Convenience constructor not in API
+ *
+ * @param agent the Agent used to populate the WorkItem's param
+ */
+ public AgentDeletedWorkItem(final Agent agent)
+ {
+ super(WorkItemType.AGENT_DELETED, null, newParams(agent, null));
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentHeartbeatWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentHeartbeatWorkItem.java
new file mode 100644
index 0000000000..bec432d8c2
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentHeartbeatWorkItem.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.qmf2.console;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * AGENT_HEARTBEAT: When the QMF Console receives heartbeats from an Agent, an AGENT_HEARTBEAT WorkItem
+ * is pushed onto the work-queue. The WorkItem's getParam() call returns a map which contains
+ * a reference to the Console Agent instance. The reference is indexed from the map using
+ * the key string "agent". There is no handle associated with this WorkItem.
+ *
+ * Note: the first heartbeat results in an AGENT_ADDED WorkItem for Agent not an AGENT_HEARTBEAT.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class AgentHeartbeatWorkItem extends AgentAccessWorkItem
+{
+ /**
+ * Construct an AgentHeartbeatWorkItem. Convenience constructor not in API
+ *
+ * @param agent the Agent used to populate the WorkItem's param
+ */
+ public AgentHeartbeatWorkItem(final Agent agent)
+ {
+ super(WorkItemType.AGENT_HEARTBEAT, null, newParams(agent, null));
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentProxy.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentProxy.java
new file mode 100644
index 0000000000..e43a242f51
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentProxy.java
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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.qmf2.console;
+
+// Misc Imports
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfException;
+
+/**
+ * This interface is implemented by the Console and provides a number of "Agent" related behaviours.
+ * <p>
+ * Arguably it would be possible to implement these directly in the org.apache.qpid.qmf2.console.Agent class but as
+ * it happens they tend to use more Console behaviours, for example refresh() and invokeMethod() are pretty much
+ * about constructing the appropriate JMS Message, so have more in common with the rest of
+ * org.apache.qpid.qmf2.console.Console.
+ * <p>
+ * The purpose of this interface is primarily about removing a circular dependency between Console and Agent so the
+ * Agent doesn't invoke these methods on a Console instance, rather it invokes them on an AgentProxy instance.
+ * <p>
+ * The following diagram illustrates the interactions between the Console, AgentProxy and the client side Agent
+ * representation.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ * @author Fraser Adams
+ */
+public interface AgentProxy
+{
+ /**
+ * Releases the Agent instance. Once called, the console application should not reference this instance again.
+ *
+ * @param agent the Agent to be destroyed.
+ */
+ public void destroy(Agent agent);
+
+ /**
+ * Request that the Agent update the value of an object's contents.
+ *
+ * @param agent the Agent to get the refresh from.
+ * @param objectId the ObjectId being queried for.
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses.
+ * @param timeout the maximum time to wait for a response, overrides default replyTimeout.
+ * @return the refreshed object.
+ */
+ public QmfConsoleData refresh(Agent agent, ObjectId objectId, String replyHandle, int timeout);
+
+ /**
+ * Invoke the named method on the named Agent.
+ *
+ * @param agent the Agent to invoke the method on.
+ * @param content an unordered set of key/value pairs comprising the method arguments.
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses.
+ * @param timeout the maximum time to wait for a response, overrides default replyTimeout.
+ * @return the MethodResult.
+ */
+ public MethodResult invokeMethod(Agent agent, Map<String, Object> content, String replyHandle, int timeout) throws QmfException;
+
+ /**
+ * Remove a Subscription.
+ *
+ * @param subscription the SubscriptionManager that we wish to remove.
+ */
+ public void removeSubscription(SubscriptionManager subscription);
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentRestartedWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentRestartedWorkItem.java
new file mode 100644
index 0000000000..45bf67f034
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/AgentRestartedWorkItem.java
@@ -0,0 +1,46 @@
+/*
+ *
+ * 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.qmf2.console;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * AGENT_RESTARTED: Sent when the QMF Console detects an Agent was restarted, an AGENT_RESTARTED WorkItem
+ * is pushed onto the work-queue. The WorkItem's getParam() call returns a map which contains
+ * a reference to the Console Agent instance. The reference is indexed from the map using
+ * the key string "agent". There is no handle associated with this WorkItem.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class AgentRestartedWorkItem extends AgentAccessWorkItem
+{
+ /**
+ * Construct an AgentRestartedWorkItem. Convenience constructor not in API
+ *
+ * @param agent the Agent used to populate the WorkItem's param
+ */
+ public AgentRestartedWorkItem(final Agent agent)
+ {
+ super(WorkItemType.AGENT_RESTARTED, null, newParams(agent, null));
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Console.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Console.java
new file mode 100644
index 0000000000..d15e4ad58d
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/Console.java
@@ -0,0 +1,2237 @@
+/*
+ *
+ * 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.qmf2.console;
+
+// JMS Imports
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+
+// Used to get the PID equivalent
+import java.lang.management.ManagementFactory;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Misc Imports
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.AMQPMessage;
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.Notifier;
+import org.apache.qpid.qmf2.common.NotifierWrapper;
+import org.apache.qpid.qmf2.common.NullQmfEventListener;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfCallback;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.SchemaClass;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.common.WorkQueue;
+
+// Reuse this class as it provides a handy mechanism to parse an options String into a Map
+import org.apache.qpid.messaging.util.AddressParser;
+
+/**
+ * The Console class is the top-level object used by a console application. All QMF console functionality
+ * is made available by this object. A console application must instatiate one of these objects.
+ * <p>
+ * If a name is supplied, it must be unique across all Consoles attached to the AMQP bus under the given
+ * domain. If no name is supplied, a unique name will be synthesized in the format: "qmfc-<hostname>.<pid>"
+ * <p>
+ * <h3>Interactions with remote Agent</h3>
+ * As noted below, some Console methods require contacting a remote Agent. For these methods, the caller
+ * has the option to either block for a (non-infinite) timeout waiting for a reply, or to allow the method
+ * to complete asynchonously. When the asynchronous approach is used, the caller must provide a unique
+ * handle that identifies the request. When the method eventually completes, a WorkItem will be placed on
+ * the work queue. The WorkItem will contain the handle that was provided to the corresponding method call.
+ * <p>
+ * The following diagram illustrates the interactions between the Console, Agent and client side Agent proxy.
+ * <p>
+ * <img src="doc-files/Console.png"/>
+ * <p>
+ * All blocking calls are considered thread safe - it is possible to have a multi-threaded implementation
+ * have multiple blocking calls in flight simultaneously.
+ * <p>
+ * <h3>Subscriptions</h3>
+ * This implementation of the QMF2 API has full support for QMF2 Subscriptions where they are supported by an Agent.
+ * <p>
+ * N.B. That the 0.12 C++ broker does not <i>actually</i> support subscriptions, however it does periodically "push"
+ * QmfConsoleData Object updates as _data indications. The Console class uses these to provide client side
+ * emulation of broker subscriptions.
+ * The System Property "disable_subscription_emulation" may be set to true to disable this behaviour.
+ * <p>
+ * The diagram below shows the relationship between the Console, the SubscriptionManager (which is used to manage the
+ * lifecycle of Subscriptions on the client side) and the local Agent representation.
+ * <p>
+ * The SubscriptionManager is also used to maintain the Subscription query to enable ManagementAgent _data indications
+ * to be tested in order to emulate Subscriptions to the broker ManagementAgent on the client side.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ * <p>
+ * <h3>Receiving Asynchronous Notifications</h3>
+ * This implementation of the QMF2 Console actually supports two independent APIs to enable clients to receive
+ * Asynchronous notifications.
+ * <p>
+ * A QmfEventListener object is used to receive asynchronously delivered WorkItems.
+ * <p>
+ * This provides an alternative (simpler) API to the official QMF2 WorkQueue API that some (including the Author)
+ * may prefer over the official API.
+ * <p>
+ * The following diagram illustrates the QmfEventListener Event model.
+ * <p>
+ * Notes
+ * <ol>
+ * <li>This is provided as an alternative to the official QMF2 WorkQueue and Notifier Event model.</li>
+ * <li>Agent and Console methods are sufficiently thread safe that it is possible to call them from a callback fired
+ * from the onEvent() method that may have been called from the JMS MessageListener. Internally the synchronous
+ * and asynchronous calls are processed on different JMS Sessions to facilitate this</li>
+ * </ol>
+ * <p>
+ * <img src="doc-files/QmfEventListenerModel.png"/>
+ * <p>
+ * The QMF2 API has a work-queue Callback approach. All asynchronous events are represented by a WorkItem object.
+ * When a QMF event occurs it is translated into a WorkItem object and placed in a FIFO queue. It is left to the
+ * application to drain this queue as needed.
+ * <p>
+ * This new API does require the application to provide a single callback. The callback is used to notify the
+ * application that WorkItem object(s) are pending on the work queue. This callback is invoked by QMF when one or
+ * more new WorkItem objects are added to the queue. To avoid any potential threading issues, the application is
+ * not allowed to call any QMF API from within the context of the callback. The purpose of the callback is to
+ * notify the application to schedule itself to drain the work queue at the next available opportunity.
+ * <p>
+ * For example, a console application may be designed using a select() loop. The application waits in the select()
+ * for any of a number of different descriptors to become ready. In this case, the callback could be written to
+ * simply make one of the descriptors ready, and then return. This would cause the application to exit the wait state,
+ * and start processing pending events.
+ * <p>
+ * The callback is represented by the Notifier virtual base class. This base class contains a single method. An
+ * application derives a custom notification handler from this class, and makes it available to the Console or
+ * Agent object.
+ * <p>
+ * The following diagram illustrates the Notifier and WorkQueue QMF2 API Event model.
+ * <p>
+ * Notes
+ * <ol>
+ * <li>There is an alternative (simpler but not officially QMF2) API based on implementing the QmfEventListener as
+ * described previously.</li>
+ * <li>BlockingNotifier is not part of QMF2 either but is how most people would probably write a Notifier.</li>
+ * <li>It's generally not necessary to use a Notifier as the Console provides a blocking getNextWorkitem() method.</li>
+ * </ol>
+ * <p>
+ * <img src="doc-files/WorkQueueEventModel.png"/>
+
+
+ * <h3>Potential Issues with Qpid versions earlier than 0.12</h3>
+ * Note 1: This uses QMF2 so requires that the "--mgmt-qmf2 yes" option is applied to the broker (this is the default
+ * from Qpid 0.10).
+ * <p>
+ * Note 2: In order to use QMF2 the app-id field needs to be set. There appears to be no way to set the AMQP 0-10
+ * specific app-id field on a message which the brokers QMFv2 implementation currently requires.
+ * <p>
+ * Gordon Sim has put together a patch for org.apache.qpid.client.message.AMQMessageDelegate_0_10
+ * Found in client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java
+ * <pre>
+ * public void setStringProperty(String propertyName, String value) throws JMSException
+ * {
+ * checkPropertyName(propertyName);
+ * checkWritableProperties();
+ * setApplicationHeader(propertyName, value);
+ *
+ * if ("x-amqp-0-10.app-id".equals(propertyName))
+ * {
+ * _messageProps.setAppId(value.getBytes());
+ * }
+ * }
+ * </pre>
+ * This gets things working.
+ * <p>
+ * A jira <a href=https://issues.apache.org/jira/browse/QPID-3302>QPID-3302</a> has been raised.
+ * This is fixed in Qpid 0.12.
+ *
+ * @author Fraser Adams
+ */
+public final class Console implements MessageListener, AgentProxy
+{
+ private static final Logger _log = LoggerFactory.getLogger(Console.class);
+
+ // Attributes
+ // ********************************************************************************************************
+
+ /**
+ * The eventListener may be a real application QmfEventListener, a NullQmfEventListener or an application
+ * Notifier wrapped in a QmfEventListener. In all cases the Console may call _eventListener.onEvent() at
+ * various places to pass a WorkItem to an asynchronous receiver.
+ */
+ private QmfEventListener _eventListener;
+
+ /**
+ * Explicitly store Agents in a ConcurrentHashMap, as we know the MessageListener thread may modify its contents.
+ */
+ private Map<String, Agent> _agents = new ConcurrentHashMap<String, Agent>();
+
+ /**
+ * This Map is used to look up a Subscription by consoleHandle.
+ */
+ private Map<String, SubscriptionManager> _subscriptionByHandle = new ConcurrentHashMap<String, SubscriptionManager>();
+
+ /**
+ * This Map is used to look up a Subscription by subscriptionId
+ */
+ private Map<String, SubscriptionManager> _subscriptionById = new ConcurrentHashMap<String, SubscriptionManager>();
+
+ /**
+ * Used to implement a thread safe queue of WorkItem objects used to implement the Notifier API
+ */
+ private WorkQueue _workQueue = new WorkQueue();
+
+ /**
+ * The name of the broker Agent is explicitly recorded when the broker Agent is discovered, we use this so
+ * we can support the synonyms "broker" and "qpidd" for the broker Agent, as its full name isn't especially
+ * easy to use givent that it contains a UUID "instance" component.
+ */
+ private String _brokerAgentName = null;
+
+ /**
+ * A flag to indicate that an Agent has been registered, used as a condition variable.
+ */
+ private boolean _agentAvailable = false;
+
+ /**
+ * The domain string is used to construct the name of the AMQP exchange to which the component's
+ * name string will be bound. If not supplied, the value of the domain defaults to "default". Both
+ * Agents and Components must belong to the same domain in order to communicate.
+ */
+ private String _domain;
+
+ /**
+ * A QMF address is composed of two parts - an optional domain string, and a mandatory
+ * name string "qmf.<domain-string>.direct/<name-string>"
+ */
+ private String _address;
+
+ /**
+ * This flag enables AGENT_* work items to be sent to the Event Listener. Note this is enabled by default
+ */
+ private boolean _discoverAgents = true;
+
+ /**
+ * This Query is set by the enableAgentDiscovery() method that takes a QmfQuery as a parameter. It is used
+ * in conjunction with _discoverAgents to decide whether to send notifications of Agent activity
+ */
+ private QmfQuery _agentQuery = null;
+
+ /**
+ * This flag disbles asynchronous behaviour such as QMF Events, Agent discovery etc. useful in simple
+ * Use Cases such as getObjects() on the broker. Note that asynchronous behaviour enabled by default.
+ */
+ private boolean _disableEvents = false;
+
+ /**
+ * If the "disable_subscription_emulation" System Property is set then we disable Console side emulation
+ * of broker subscriptions
+ */
+ private boolean _subscriptionEmulationEnabled = !Boolean.getBoolean("disable_subscription_emulation");
+
+ /**
+ * Various timeouts used internally.
+ * replyTimeout is the default maximum time we wait for synchronous responses
+ * agentTimeout is the maximum time we wait for any Agent activity before expiring the Agent
+ * subscriptionDuration is the default maximum time we keep a subscription active
+ */
+ private int _replyTimeout = 10;
+ private int _agentTimeout = 60; // 1 minute
+ private int _subscriptionDuration = 300; // 5 minutes
+
+ /**
+ * This timer is used tidy up Subscription references where a Subscription has expired. Ideally a client should
+ * call cancelSubscription(), but we can't rely on it.
+ */
+ private Timer _timer;
+
+ /**
+ * Various JMS related fields
+ */
+ private Connection _connection = null;
+ private Session _asyncSession;
+ private Session _syncSession;
+ private MessageConsumer _eventConsumer;
+ private MessageConsumer _responder;
+ private MessageConsumer _asyncResponder;
+ private MessageProducer _requester;
+ private MessageProducer _broadcaster;
+ private Destination _replyAddress;
+ private Destination _asyncReplyAddress;
+
+ // private implementation methods
+ // ********************************************************************************************************
+
+ /**
+ * Send an asynchronous _agent_locate_request to the topic broadcast address with the subject
+ * "console.request.agent_locate". This should cause all active Agents to respond on the async
+ * direct address, which gets handled by onMessage()
+ */
+ private void broadcastAgentLocate()
+ {
+ try
+ {
+ Message request = AMQPMessage.createListMessage(_syncSession);
+ request.setJMSReplyTo(_asyncReplyAddress);
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_agent_locate_request");
+ request.setStringProperty("qpid.subject", "console.request.agent_locate");
+ AMQPMessage.setList(request, Collections.emptyList());
+ _broadcaster.send(request);
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in broadcastAgentLocate()", jmse.getMessage());
+ }
+ }
+
+ /**
+ * Check whether any of the registered Agents has expired by comparing their timestamp against the
+ * current time. We explicitly use an iterator rather than a foreach loop because if the Agent has
+ * expired we want to remove it and the only safe way to do that whilst still iterating is to use
+ * iterator.remove() and the foreach loop hides the underlying iterator from us.
+ */
+ private void handleAgentExpiry()
+ {
+ long currentTime = System.currentTimeMillis()*1000000l;
+
+ // Use the iterator approach rather than foreach as we may want to call iterator.remove() to zap an entry
+ Iterator<Agent> i = _agents.values().iterator();
+ while (i.hasNext())
+ {
+ Agent agent = i.next();
+ // Get the time difference in seconds between now and the last Agent update.
+ long diff = (currentTime - agent.getTimestamp())/1000000000l;
+ if (diff > _agentTimeout)
+ {
+ if (agent.getVendor().equals("apache.org") && agent.getProduct().equals("qpidd"))
+ {
+ _brokerAgentName = null;
+ }
+ agent.deactivate();
+ i.remove();
+ _log.info("Agent {} has expired", agent.getName());
+ if (_discoverAgents && (_agentQuery == null || _agentQuery.evaluate(agent)))
+ {
+ _eventListener.onEvent(new AgentDeletedWorkItem(agent));
+ }
+ }
+ }
+ }
+
+ /**
+ * MessageListener for QMF2 Agent Events, Hearbeats and Asynchronous data indications
+ *
+ * @param message the JMS Message passed to the listener
+ */
+ public void onMessage(Message message)
+ {
+ try
+ {
+ String agentName = QmfData.getString(message.getObjectProperty("qmf.agent"));
+ String content = QmfData.getString(message.getObjectProperty("qmf.content"));
+ String opcode = QmfData.getString(message.getObjectProperty("qmf.opcode"));
+ //String routingKey = ((javax.jms.Topic)message.getJMSDestination()).getTopicName();
+ //String contentType = ((org.apache.qpid.client.message.AbstractJMSMessage)message).getContentType();
+
+//System.out.println();
+//System.out.println("agentName = " + agentName);
+//System.out.println("content = " + content);
+//System.out.println("opcode = " + opcode);
+//System.out.println("routingKey = " + routingKey);
+//System.out.println("contentType = " + contentType);
+
+ if (opcode.equals("_agent_heartbeat_indication") || opcode.equals("_agent_locate_response"))
+ { // This block handles Agent lifecycle information (discover, register, delete)
+ if (_agents.containsKey(agentName))
+ { // This block handles Agents that have previously been registered
+ Agent agent = _agents.get(agentName);
+ long originalEpoch = agent.getEpoch();
+
+ // If we already know about an Agent we simply update the Agent's state using initialise()
+ agent.initialise(AMQPMessage.getMap(message));
+
+ // If the Epoch has changed it means the Agent has been restarted so we send a notification
+ if (agent.getEpoch() != originalEpoch)
+ {
+ agent.clearSchemaCache(); // Clear cache to force a lookup
+ List<SchemaClassId> classes = getClasses(agent);
+ getSchema(classes, agent); // Discover the schema for this Agent and cache it
+ _log.info("Agent {} has been restarted", agentName);
+ if (_discoverAgents && (_agentQuery == null || _agentQuery.evaluate(agent)))
+ {
+ _eventListener.onEvent(new AgentRestartedWorkItem(agent));
+ }
+ }
+ else
+ { // Otherwise just send a heartbeat notification
+ _log.info("Agent {} heartbeat", agent.getName());
+ if (_discoverAgents && (_agentQuery == null || _agentQuery.evaluate(agent)))
+ {
+ _eventListener.onEvent(new AgentHeartbeatWorkItem(agent));
+ }
+ }
+ }
+ else
+ { // This block handles Agents that haven't already been registered
+ Agent agent = new Agent(AMQPMessage.getMap(message), this);
+ List<SchemaClassId> classes = getClasses(agent);
+ getSchema(classes, agent); // Discover the schema for this Agent and cache it
+ _agents.put(agentName, agent);
+ _log.info("Adding Agent {}", agentName);
+
+ // If the Agent is the Broker Agent we record it as _brokerAgentName to make retrieving
+ // the Agent more "user friendly" than using the full Agent name.
+ if (agent.getVendor().equals("apache.org") && agent.getProduct().equals("qpidd"))
+ {
+ _log.info("Recording {} as _brokerAgentName", agentName);
+ _brokerAgentName = agentName;
+ }
+
+ // Notify any waiting threads that an Agent has been registered. Note that we only notify if
+ // we've already found the broker Agent to avoid a race condition in addConnection(), as another
+ // Agent could in theory trigger this block first. In addConnection() we *explicitly* want to
+ // wait for the broker Agent to become available.
+ if (_brokerAgentName != null)
+ {
+ synchronized(this)
+ {
+ _agentAvailable = true;
+ notifyAll();
+ }
+ }
+
+ if (_discoverAgents && (_agentQuery == null || _agentQuery.evaluate(agent)))
+ {
+ _eventListener.onEvent(new AgentAddedWorkItem(agent));
+ }
+ }
+
+ // The broker Agent sends periodic heartbeats and that Agent should *always* be available given
+ // a running broker, so we should get here every "--mgmt-pub-interval" seconds or so, so it's
+ // a good place to periodically check for the expiry of any other Agents.
+ handleAgentExpiry();
+ return;
+ }
+
+ if (!_agents.containsKey(agentName))
+ {
+ _log.info("Ignoring Event from unregistered Agent {}", agentName);
+ return;
+ }
+
+ Agent agent = _agents.get(agentName);
+ if (!agent.eventsEnabled())
+ {
+ _log.info("{} has disabled Event reception, ignoring Event", agentName);
+ return;
+ }
+
+ // If we get to here the Agent from whence the Event came should be registered and should
+ // have Event reception enabled, so we should be able to send events to the EventListener
+
+ Handle handle = new Handle(message.getJMSCorrelationID());
+ if (opcode.equals("_method_response") || opcode.equals("_exception"))
+ {
+ if (AMQPMessage.isAMQPMap(message))
+ {
+ _eventListener.onEvent(
+ new MethodResponseWorkItem(handle, new MethodResult(AMQPMessage.getMap(message)))
+ );
+ }
+ else
+ {
+ _log.info("onMessage() Received Method Response message in incorrect format");
+ }
+ }
+
+ // Query Response. The only asynchronous query response we expect to see is the result of an async
+ // refresh() call on QmfConsoleData so the number of results in the returned list *should* be one.
+ if (opcode.equals("_query_response") && content.equals("_data"))
+ {
+ if (AMQPMessage.isAMQPList(message))
+ {
+ List<Map> list = AMQPMessage.getList(message);
+ for (Map m : list)
+ {
+ _eventListener.onEvent(new ObjectUpdateWorkItem(handle, new QmfConsoleData(m, agent)));
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Query Response message in incorrect format");
+ }
+ }
+
+ // This block handles responses to createSubscription and refreshSubscription
+ if (opcode.equals("_subscribe_response"))
+ {
+ if (AMQPMessage.isAMQPMap(message))
+ {
+ String correlationId = message.getJMSCorrelationID();
+ SubscribeParams params = new SubscribeParams(correlationId, AMQPMessage.getMap(message));
+ String subscriptionId = params.getSubscriptionId();
+
+ if (subscriptionId != null && correlationId != null)
+ {
+ SubscriptionManager subscription = _subscriptionById.get(subscriptionId);
+ if (subscription == null)
+ { // This is a createSubscription response so the correlationId should be the consoleHandle
+ subscription = _subscriptionByHandle.get(correlationId);
+ if (subscription != null)
+ {
+ _subscriptionById.put(subscriptionId, subscription);
+ subscription.setSubscriptionId(subscriptionId);
+ subscription.setDuration(params.getLifetime());
+ String replyHandle = subscription.getReplyHandle();
+ if (replyHandle == null)
+ {
+ subscription.signal();
+ }
+ else
+ {
+ _eventListener.onEvent(new SubscribeResponseWorkItem(new Handle(replyHandle), params));
+ }
+ }
+ }
+ else
+ { // This is a refreshSubscription response
+ params.setConsoleHandle(subscription.getConsoleHandle());
+ subscription.setDuration(params.getLifetime());
+ subscription.refresh();
+ _eventListener.onEvent(new SubscribeResponseWorkItem(handle, params));
+ }
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Subscribe Response message in incorrect format");
+ }
+ }
+
+ // Subscription Indication - in other words the asynchronous results of a Subscription
+ if (opcode.equals("_data_indication") && content.equals("_data"))
+ {
+ if (AMQPMessage.isAMQPList(message))
+ {
+ String consoleHandle = handle.getCorrelationId();
+ if (consoleHandle != null && _subscriptionByHandle.containsKey(consoleHandle))
+ { // If we have a valid consoleHandle the data has come from a "real" Subscription.
+ List<Map> list = AMQPMessage.getList(message);
+ List<QmfConsoleData> resultList = new ArrayList<QmfConsoleData>(list.size());
+ for (Map m : list)
+ {
+ resultList.add(new QmfConsoleData(m, agent));
+ }
+ _eventListener.onEvent(
+ new SubscriptionIndicationWorkItem(new SubscribeIndication(consoleHandle, resultList))
+ );
+ }
+ else if (_subscriptionEmulationEnabled && agentName.equals(_brokerAgentName))
+ { // If the data has come from is the broker Agent we emulate a Subscription on the Console
+ for (SubscriptionManager subscription : _subscriptionByHandle.values())
+ {
+ QmfQuery query = subscription.getQuery();
+ if (subscription.getAgent().getName().equals(_brokerAgentName) &&
+ query.getTarget() == QmfQueryTarget.OBJECT)
+ { // Only evaluate broker Agent subscriptions with QueryTarget == OBJECT on the Console.
+ long objectEpoch = 0;
+ consoleHandle = subscription.getConsoleHandle();
+ List<Map> list = AMQPMessage.getList(message);
+ List<QmfConsoleData> resultList = new ArrayList<QmfConsoleData>(list.size());
+ for (Map m : list)
+ { // Evaluate the QmfConsoleData object against the query
+ QmfConsoleData object = new QmfConsoleData(m, agent);
+ if (query.evaluate(object))
+ {
+ long epoch = object.getObjectId().getAgentEpoch();
+ objectEpoch = (epoch > objectEpoch && !object.isDeleted()) ? epoch : objectEpoch;
+ resultList.add(object);
+ }
+ }
+
+ if (resultList.size() > 0)
+ { // If there are any results available after evaluating the query we deliver them
+ // via a SubscribeIndicationWorkItem.
+
+ // Before we send the WorkItem we take a peek at the Agent Epoch value that forms
+ // part of the ObjectID and compare it against the current Epoch value. If they
+ // are different we send an AgentRestartedWorkItem. We *normally* check for Epoch
+ // changes when we receive heartbeat indications, but unfortunately the broker
+ // ManagementAgent pushes data *before* it pushes heartbeats. Its more useful
+ // however for clients to know that an Agent has been restarted *before* they get
+ // data from the restarted Agent (in case they need to reset any state).
+ if (objectEpoch > agent.getEpoch())
+ {
+ agent.setEpoch(objectEpoch);
+ agent.clearSchemaCache(); // Clear cache to force a lookup
+ List<SchemaClassId> classes = getClasses(agent);
+ getSchema(classes, agent); // Discover the schema for this Agent and cache it
+ _log.info("Agent {} has been restarted", agentName);
+ if (_discoverAgents && (_agentQuery == null || _agentQuery.evaluate(agent)))
+ {
+ _eventListener.onEvent(new AgentRestartedWorkItem(agent));
+ }
+ }
+
+ _eventListener.onEvent(
+ new SubscriptionIndicationWorkItem(
+ new SubscribeIndication(consoleHandle, resultList))
+ );
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Subscribe Indication message in incorrect format");
+ }
+ }
+
+ // The results of an Event delivered from an Agent
+ if (opcode.equals("_data_indication") && content.equals("_event"))
+ { // There are differences in the type of message sent by Qpid 0.8 and 0.10 onwards.
+ if (AMQPMessage.isAMQPMap(message))
+ { // 0.8 broker passes Events as amqp/map encoded as MapMessages (we convert into java.util.Map)
+ _eventListener.onEvent(new EventReceivedWorkItem(agent, new QmfEvent(AMQPMessage.getMap(message))));
+ }
+ else if (AMQPMessage.isAMQPList(message))
+ { // 0.10 and above broker passes Events as amqp/list encoded as BytesMessage (needs decoding)
+ // 0.20 encodes amqp/list in a MapMessage!!?? AMQPMessage hopefully abstracts this detail.
+ List<Map> list = AMQPMessage.getList(message);
+ for (Map m : list)
+ {
+ _eventListener.onEvent(new EventReceivedWorkItem(agent, new QmfEvent(m)));
+ }
+ }
+ else
+ {
+ _log.info("onMessage() Received Event message in incorrect format");
+ }
+ }
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in onMessage()", jmse.getMessage());
+ }
+ } // end of onMessage()
+
+ /**
+ * Retrieve the schema for a List of classes.
+ * This method explicitly retrieves the schema from the remote Agent and is generally used for schema
+ * discovery when an Agent is added or updated.
+ *
+ * @param classes the list of SchemaClassId of the classes who's schema we want to retrieve
+ * @param agent the Agent we want to retrieve the schema from
+ */
+ private List<SchemaClass> getSchema(final List<SchemaClassId> classes, final Agent agent)
+ {
+ List<SchemaClass> results = new ArrayList<SchemaClass>();
+ for (SchemaClassId classId : classes)
+ {
+ agent.setSchema(classId, Collections.<SchemaClass>emptyList()); // Clear Agent's schema value for classId
+ results.addAll(getSchema(classId, agent));
+ }
+ return results;
+ }
+
+ /**
+ * Perform a query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects.
+ * If replyHandle is null this method will block until the agent replies, or the timeout expires.
+ * Once the timeout expires, all data retrieved to date is returned. If replyHandle is non-null an
+ * asynchronous request is performed
+ *
+ * @param agent the Agent being queried
+ * @param query the ObjectId or SchemaClassId being queried for.
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses
+ * @param timeout the time to wait for a reply from the Agent, a value of -1 means use the default timeout
+ * @return a List of QMF Objects describing that class
+ */
+ private List<QmfConsoleData> getObjects(final Agent agent, final QmfData query,
+ final String replyHandle, int timeout)
+ {
+ String agentName = agent.getName();
+ timeout = (timeout < 1) ? _replyTimeout : timeout;
+ List<QmfConsoleData> results = Collections.emptyList();
+ try
+ {
+ Destination destination = (replyHandle == null) ? _replyAddress : _asyncReplyAddress;
+ MapMessage request = _syncSession.createMapMessage();
+ request.setJMSReplyTo(destination);
+ request.setJMSCorrelationID(replyHandle);
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_query_request");
+ request.setStringProperty("qpid.subject", agentName);
+
+ // Create a QMF Query for an "OBJECT" target using either a schema ID or object ID
+ String queryType = (query instanceof SchemaClassId) ? "_schema_id" : "_object_id";
+ request.setObject("_what", "OBJECT");
+ request.setObject(queryType, query.mapEncode());
+
+ // Wrap request & response in synchronized block in case any other threads invoke a request
+ // it would be somewhat unfortunate if their response got interleaved with ours!!
+ synchronized(this)
+ {
+ _requester.send(request);
+ if (replyHandle == null)
+ {
+ boolean lastResult = true;
+ ArrayList<QmfConsoleData> partials = new ArrayList<QmfConsoleData>();
+ do
+ { // Wrap in a do/while loop to cater for the case where the Agent may send partial results.
+ Message response = _responder.receive(timeout*1000);
+ if (response == null)
+ {
+ _log.info("No response received in getObjects()");
+ return partials;
+ }
+
+ lastResult = !response.propertyExists("partial");
+
+ if (AMQPMessage.isAMQPList(response))
+ {
+ List<Map> mapResults = AMQPMessage.getList(response);
+ partials.ensureCapacity(partials.size() + mapResults.size());
+ for (Map content : mapResults)
+ {
+ partials.add(new QmfConsoleData(content, agent));
+ }
+ }
+ else if (AMQPMessage.isAMQPMap(response))
+ {
+ // Error responses are returned as MapMessages, though they are being ignored here.
+ //QmfData exception = new QmfData(AMQPMessage.getMap(response));
+ //System.out.println(agentName + " " + exception.getStringValue("error_text"));
+ }
+ else
+ {
+ _log.info("getObjects() Received response message in incorrect format");
+ }
+ } while (!lastResult);
+ results = partials;
+ }
+ }
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in getObjects()", jmse.getMessage());
+ }
+ return results;
+ }
+
+ // methods implementing AgentProxy interface
+ // ********************************************************************************************************
+
+ /**
+ * Releases the specified Agent instance. Once called, the console application should not reference this
+ * instance again.
+ * <p>
+ * Intended to by called by the AgentProxy. Shouldn't generally be called directly by Console applications.
+ *
+ * @param agent the Agent that we wish to destroy.
+ */
+ public void destroy(final Agent agent)
+ {
+ handleAgentExpiry();
+ }
+
+ /**
+ * Request that the Agent update the value of an object's contents.
+ * <p>
+ * Intended to by called by the AgentProxy. Shouldn't generally be called directly by Console applications.
+ *
+ * @param agent the Agent to get the refresh from.
+ * @param objectId the ObjectId being queried for
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses
+ * @param timeout the time to wait for a reply from the Agent, a value of -1 means use the default timeout
+ * @return the refreshed object
+ */
+ public QmfConsoleData refresh(final Agent agent, final ObjectId objectId, final String replyHandle, final int timeout)
+ {
+ List<QmfConsoleData> objects = getObjects(agent, objectId, replyHandle, timeout);
+ return (objects.size() == 0) ? null : objects.get(0);
+ }
+
+ /**
+ * Invoke the named method on the named Agent.
+ * <p>
+ * Intended to by called by the AgentProxy. Shouldn't generally be called directly by Console applications.
+ *
+ * @param agent the Agent to invoke the method on.
+ * @param content an unordered set of key/value pairs comprising the method arguments.
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses
+ * @param timeout the time to wait for a reply from the Agent, a value of -1 means use the default timeout
+ * @return the method response Arguments in Map form
+ */
+ public MethodResult invokeMethod(final Agent agent, final Map<String, Object> content,
+ final String replyHandle, int timeout) throws QmfException
+ {
+ if (!agent.isActive())
+ {
+ throw new QmfException("Called invokeMethod() with inactive agent");
+ }
+ String agentName = agent.getName();
+ timeout = (timeout < 1) ? _replyTimeout : timeout;
+ try
+ {
+ Destination destination = (replyHandle == null) ? _replyAddress : _asyncReplyAddress;
+ MapMessage request = _syncSession.createMapMessage();
+ request.setJMSReplyTo(destination);
+ request.setJMSCorrelationID(replyHandle);
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_method_request");
+ request.setStringProperty("qpid.subject", agentName);
+
+ for (Map.Entry<String, Object> entry : content.entrySet())
+ {
+ request.setObject(entry.getKey(), entry.getValue());
+ }
+
+ // Wrap request & response in synchronized block in case any other threads invoke a request
+ // it would be somewhat unfortunate if their response got interleaved with ours!!
+ synchronized(this)
+ {
+ _requester.send(request);
+ if (replyHandle == null)
+ { // If this is a synchronous request get the response
+ Message response = _responder.receive(timeout*1000);
+ if (response == null)
+ {
+ _log.info("No response received in invokeMethod()");
+ throw new QmfException("No response received for Console.invokeMethod()");
+ }
+ MethodResult result = new MethodResult(AMQPMessage.getMap(response));
+ QmfException exception = result.getQmfException();
+ if (exception != null)
+ {
+ throw exception;
+ }
+ return result;
+ }
+ }
+ // If this is an asynchronous request return without waiting for a response
+ return null;
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in invokeMethod()", jmse.getMessage());
+ throw new QmfException(jmse.getMessage());
+ }
+ }
+
+ /**
+ * Remove a Subscription.
+ *
+ * @param subscription the SubscriptionManager that we wish to remove.
+ */
+ public void removeSubscription(final SubscriptionManager subscription)
+ {
+ String consoleHandle = subscription.getConsoleHandle();
+ String subscriptionId = subscription.getSubscriptionId();
+ if (consoleHandle != null)
+ {
+ _subscriptionByHandle.remove(consoleHandle);
+ }
+ if (subscriptionId != null)
+ {
+ _subscriptionById.remove(subscriptionId);
+ }
+ }
+
+ // QMF API Methods
+ // ********************************************************************************************************
+
+ /**
+ * Constructor that provides defaults for name and domain and has no Notifier/Listener
+ * <p>
+ * Warning!! If more than one Console is needed in a process be sure to use the Constructor that allows one to
+ * supply a name as &lt;hostname&gt;.&lt;pid&gt; isn't unique enough and will result in "odd results" (trust me!!).
+ */
+ public Console() throws QmfException
+ {
+ this(null, null, null, null);
+ }
+
+ /**
+ * Constructor that provides defaults for name and domain and takes a Notifier/Listener.
+ * <p>
+ * Warning!! If more than one Console is needed in a process be sure to use the Constructor that allows one to
+ * supply a name as &lt;hostname&gt;.&lt;pid&gt; isn't unique enough and will result in "odd results" (trust me!!).
+ *
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread. This API may be simpler and more convenient
+ * than the QMF2 Notifier API for many applications.
+ */
+ public Console(final QmfCallback notifier) throws QmfException
+ {
+ this(null, null, notifier, null);
+ }
+
+ /**
+ * Main constructor, creates a Console, but does NOT start it, that requires us to do addConnection()
+ *
+ * @param name if no name is supplied we synthesise one in the format: <pre>"qmfc-&lt;hostname&gt;.&lt;pid&gt;"</pre>
+ * if we can, otherwise we create a name using a randomUUID.
+ * <p>
+ * Warning!! If more than one Console is needed in a process be sure to supply a name as
+ * &lt;hostname&gt;.&lt;pid&gt; isn't unique enough and will result in "odd results" (trust me!!).
+ * @param domain the QMF "domain". A QMF address is composed of two parts - an optional domain string, and a
+ * mandatory name string <pre>"qmf.&lt;domain-string&gt;.direct/&lt;name-string&gt;"</pre>
+ * The domain string is used to construct the name of the AMQP exchange to which the component's
+ * name string will be bound. If not supplied, the value of the domain defaults to "default". Both
+ * Agents and Components must belong to the same domain in order to communicate.
+ * @param notifier this may be either a QMF2 API Notifier object OR a QMFEventListener.
+ * <p>
+ * The latter is an alternative API that avoids the need for an explicit Notifier thread to be created the
+ * EventListener is called from the JMS MessageListener thread. This API may be simpler and more convenient
+ * than the QMF2 Notifier API for many applications.
+ * @param options a String representation of a Map containing the options in the form
+ * <pre>"{replyTimeout:&lt;value&gt;, agentTimeout:&lt;value&gt;, subscriptionDuration:&lt;value&gt;}"</pre>
+ * they are all optional and may appear in any order.
+ * <pre>
+ * <b>replyTimeout</b>=&lt;default for all blocking calls&gt;
+ * <b>agentTimeout</b>=&lt;default timeout for agent heartbeat&gt;,
+ * <b>subscriptionDuration</b>=&lt;default lifetime of a subscription&gt;
+ * </pre>
+ */
+ public Console(String name, final String domain,
+ final QmfCallback notifier, final String options) throws QmfException
+ {
+ if (name == null)
+ {
+ // ManagementFactory.getRuntimeMXBean().getName()) returns the name representing the running virtual machine.
+ // The returned name string can be any arbitrary string and a Java virtual machine implementation can choose
+ // to embed platform-specific useful information in the returned name string.
+ // As it happens on Linux the format for this is PID@hostname
+ String vmName = ManagementFactory.getRuntimeMXBean().getName();
+ String[] split = vmName.split("@");
+ if (split.length == 2)
+ {
+ name = "qmfc-" + split[1] + "." + split[0];
+ }
+ else
+ {
+ name = "qmfc-" + UUID.randomUUID();
+ }
+ }
+
+ _domain = (domain == null) ? "default" : domain;
+ _address = "qmf." + _domain + ".direct" + "/" + name;
+
+ if (notifier == null)
+ {
+ _eventListener = new NullQmfEventListener();
+ }
+ else if (notifier instanceof Notifier)
+ {
+ _eventListener = new NotifierWrapper((Notifier)notifier, _workQueue);
+ }
+ else if (notifier instanceof QmfEventListener)
+ {
+ _eventListener = (QmfEventListener)notifier;
+ }
+ else
+ {
+ throw new QmfException("QmfCallback listener must be either a Notifier or QmfEventListener");
+ }
+
+ if (options != null)
+ { // We wrap the Map in a QmfData object to avoid potential class cast issues with the parsed options
+ QmfData optMap = new QmfData(new AddressParser(options).map());
+ if (optMap.hasValue("replyTimeout"))
+ {
+ _replyTimeout = (int)optMap.getLongValue("replyTimeout");
+ }
+
+ if (optMap.hasValue("agentTimeout"))
+ {
+ _agentTimeout = (int)optMap.getLongValue("agentTimeout");
+ }
+
+ if (optMap.hasValue("subscriptionDuration"))
+ {
+ _subscriptionDuration = (int)optMap.getLongValue("subscriptionDuration");
+ }
+ }
+ }
+
+ /**
+ * Release the Console's resources.
+ */
+ public void destroy()
+ {
+ try
+ {
+ if (_connection != null)
+ {
+ removeConnection(_connection);
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ // Ignore as we've already tested for _connection != null this should never occur
+ }
+ }
+
+ /**
+ * Connect the console to the AMQP cloud.
+ *
+ * @param conn a javax.jms.Connection
+ */
+ public void addConnection(final Connection conn) throws QmfException
+ {
+ addConnection(conn, "");
+ }
+
+ /**
+ * Connect the console to the AMQP cloud.
+ * <p>
+ * This is an extension to the standard QMF2 API allowing the user to specify address options in order to allow
+ * finer control over the Console's request and reply queues, e.g. explicit name, non-default size or durability.
+ *
+ * @param conn a javax.jms.Connection
+ * @param addressOptions options String giving finer grained control of the receiver queue.
+ * <p>
+ * As an example the following gives the Console's queues the name test-console, size = 500000000 and ring policy.
+ * <pre>
+ * " ; {link: {name:'test-console', x-declare: {arguments: {'qpid.policy_type': ring, 'qpid.max_size': 500000000}}}}"
+ * </pre>
+ * Note that the Console uses several queues so this will actually create a test-console queue plus a
+ * test-console-async queue and a test-console-event queue.
+ * <p>
+ * If a name parameter is not present temporary queues will be created, but the other options will still be applied.
+ */
+ public void addConnection(final Connection conn, final String addressOptions) throws QmfException
+ {
+ // Make the test and set of _connection synchronized just in case multiple threads attempt to add a _connection
+ // to the same Console instance at the same time.
+ synchronized(this)
+ {
+ if (_connection != null)
+ {
+ throw new QmfException("Multiple connections per Console is not supported");
+ }
+ _connection = conn;
+ }
+ try
+ {
+ String syncReplyAddressOptions = addressOptions;
+ String asyncReplyAddressOptions = addressOptions;
+ String eventAddressOptions = addressOptions;
+
+ if (!addressOptions.equals(""))
+ { // If there are address options supplied we need to check if a name parameter is present.
+ String[] split = addressOptions.split("name");
+ if (split.length == 2)
+ { // If options contains a name parameter we extract it and create variants for async and event queues.
+ split = split[1].split("[,}]"); // Look for the end of the key/value block
+ String nameValue = split[0].replaceAll("[ :'\"]", ""); // Remove initial colon, space any any quotes.
+ // Hopefully at this point nameValue is actually the value of the name parameter.
+ asyncReplyAddressOptions = asyncReplyAddressOptions.replace(nameValue, nameValue + "-async");
+ eventAddressOptions = eventAddressOptions.replace(nameValue, nameValue + "-event");
+ }
+ }
+
+ String topicBase = "qmf." + _domain + ".topic";
+ _syncSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Create a MessageProducer for the QMF topic address used to broadcast requests
+ Destination topicAddress = _syncSession.createQueue(topicBase);
+ _broadcaster = _syncSession.createProducer(topicAddress);
+
+ // If Asynchronous Behaviour is enabled we create the Queues used to receive async responses
+ // Data Indications, QMF Events, Heartbeats etc. from the broker (or other Agents).
+ if (!_disableEvents)
+ {
+ // TODO it should be possible to bind _eventConsumer and _asyncResponder to the same queue
+ // if I can figure out the correct AddressString to use, probably not a big deal though.
+
+ _asyncSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Set up MessageListener on the Event Address
+ Destination eventAddress = _asyncSession.createQueue(topicBase + "/agent.ind.#" + eventAddressOptions);
+ _eventConsumer = _asyncSession.createConsumer(eventAddress);
+ _eventConsumer.setMessageListener(this);
+
+ // Create the asynchronous JMSReplyTo _replyAddress and MessageConsumer
+ _asyncReplyAddress = _asyncSession.createQueue(_address + ".async" + asyncReplyAddressOptions);
+ _asyncResponder = _asyncSession.createConsumer(_asyncReplyAddress);
+ _asyncResponder.setMessageListener(this);
+ }
+
+ // I've extended the synchronized block to include creating the _requester and _responder. I don't believe
+ // that this is strictly necessary, but it stops findbugs moaning about inconsistent synchronization
+ // so makes sense if only to get that warm and fuzzy feeling of keeping findbugs happy :-)
+ synchronized(this)
+ {
+ // Create a MessageProducer for the QMF direct address, mainly used for request/response
+ Destination directAddress = _syncSession.createQueue("qmf." + _domain + ".direct");
+ _requester = _syncSession.createProducer(directAddress);
+
+ // Create the JMSReplyTo _replyAddress and MessageConsumer
+ _replyAddress = _syncSession.createQueue(_address + syncReplyAddressOptions);
+ _responder = _syncSession.createConsumer(_replyAddress);
+
+ _connection.start();
+
+ // If Asynchronous Behaviour is disabled we create an Agent instance to represent the broker
+ // ManagementAgent the only info that needs to be populated is the _name and we can use the
+ // "broker" synonym. We populate this fake Agent so getObjects() behaviour is consistent whether
+ // we've any received *real* Agent updates or not.
+ if (_disableEvents)
+ {
+ _brokerAgentName = "broker";
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("_name", _brokerAgentName);
+ Agent agent = new Agent(map, this);
+ _agents.put(_brokerAgentName, agent);
+ _agentAvailable = true;
+ }
+ else
+ {
+ // If Asynchronous Behaviour is enabled Broadcast an Agent Locate message to get Agent info quickly.
+ broadcastAgentLocate();
+ }
+
+ // Wait until the Broker Agent has been located (this should generally be pretty quick)
+ while (!_agentAvailable)
+ {
+ long startTime = System.currentTimeMillis();
+ try
+ {
+ wait(_replyTimeout*1000);
+ }
+ catch (InterruptedException ie)
+ {
+ continue;
+ }
+ // Measure elapsed time to test against spurious wakeups and ensure we really have timed out
+ long elapsedTime = (System.currentTimeMillis() - startTime)/1000;
+ if (!_agentAvailable && elapsedTime >= _replyTimeout)
+ {
+ _log.info("Broker Agent not found");
+ throw new QmfException("Broker Agent not found");
+ }
+ }
+
+ // Timer used for tidying up Subscriptions.
+ _timer = new Timer(true);
+ }
+ }
+ catch (JMSException jmse)
+ {
+ // If we can't create the QMF Destinations there's not much else we can do
+ _log.info("JMSException {} caught in addConnection()", jmse.getMessage());
+ throw new QmfException("Failed to create sessions or destinations " + jmse.getMessage());
+ }
+ }
+
+ /**
+ * Remove the AMQP connection from the console. Un-does the addConnection() operation, and releases
+ * any Agents associated with the connection. All blocking methods are unblocked and given a failure
+ * status. All outstanding asynchronous operations are cancelled without producing WorkItems.
+ *
+ * @param conn a javax.jms.Connection
+ */
+ public void removeConnection(final Connection conn) throws QmfException
+ {
+ if (conn != _connection)
+ {
+ throw new QmfException("Attempt to delete unknown connection");
+ }
+
+ try
+ {
+ _timer.cancel();
+ _connection.close(); // Should we close() the connection here or just stop() it ???
+ }
+ catch (JMSException jmse)
+ {
+ throw new QmfException("Failed to remove connection, caught JMSException " + jmse.getMessage());
+ }
+ _connection = null;
+ }
+
+ /**
+ * Get the AMQP address this Console is listening to.
+ *
+ * @return the console's replyTo address. Note that there are actually two, there's a synchronous one
+ * which is the return address for synchronous request/response type invocations and there's an
+ * asynchronous address with a ".async" suffix which is the return address for asynchronous invocations
+ */
+ public String getAddress()
+ {
+ return _address;
+ }
+
+ /**
+ * Query for the presence of a specific agent in the QMF domain. Returns a class Agent if the agent is
+ * present. If the agent is not already known to the console, this call will send a query for the agent
+ * and block (with default timeout override) waiting for a response.
+ *
+ * @param agentName the name of the Agent to be returned.
+ * <p>
+ * "broker" or "qpidd" may be used as synonyms for the broker Agent name and the method will try to match
+ * agentName against the Agent name, the Agent product name and will also check if the Agent name contains
+ * the agentName String.
+ * <p>
+ * Checking against a partial match is useful because the full Agent name has a UUID representing
+ * the "instance" so it's hard to know the full name without having actually retrieved the Agent.
+ * @return the found Agent instance or null if an Agent of the given name could not be found
+ */
+ public Agent findAgent(final String agentName)
+ {
+ return findAgent(agentName, _replyTimeout);
+ }
+
+ /**
+ * Query for the presence of a specific agent in the QMF domain. Returns a class Agent if the agent is
+ * present. If the agent is not already known to the console, this call will send a query for the agent
+ * and block (with specified timeout override) waiting for a response.
+ *
+ * @param agentName the name of the Agent to be returned.
+ * <p>
+ * "broker" or "qpidd" may be used as synonyms for the broker Agent name and the method will try to match
+ * agentName against the Agent name, the Agent product name and will also check if the Agent name contains
+ * the agentName String.
+ * <p>
+ * Checking against a partial match is useful because the full Agent name has a UUID representing
+ * the "instance" so it's hard to know the full name without having actually retrieved the Agent.
+ * @param timeout the time (in seconds) to wait for the Agent to be found
+ * @return the found Agent instance or null if an Agent of the given name could not be found
+ */
+ public Agent findAgent(final String agentName, final int timeout)
+ {
+ Agent agent = getAgent(agentName);
+ if (agent == null)
+ {
+ broadcastAgentLocate();
+ long startTime = System.currentTimeMillis();
+ do
+ {
+ agent = getAgent(agentName);
+ if (agent != null)
+ {
+ return agent;
+ }
+
+ synchronized(this)
+ {
+ try
+ { // At worst this behaves as a 1 second sleep, but will return sooner if an Agent gets registered
+ wait(1000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+ } while ((System.currentTimeMillis() - startTime)/1000 < _replyTimeout);
+ }
+ return agent;
+ }
+
+ /**
+ * Called to enable the asynchronous Agent Discovery process. Once enabled, AGENT_ADDED and AGENT_DELETED
+ * work items can arrive on the WorkQueue.
+ * <p>
+ * Note that in this implementation Agent Discovery is enabled by default. Note too that enableAgentDiscovery()
+ * or disableAgentDiscovery() should be called before addConnection(), as this starts a MessageListener Thread
+ * that could place events on the work queue.
+ */
+ public void enableAgentDiscovery()
+ {
+ _discoverAgents = true;
+ _agentQuery = null;
+ }
+
+ /**
+ * Called to enable the asynchronous Agent Discovery process. Once enabled, AGENT_ADDED and AGENT_DELETED
+ * work items can arrive on the WorkQueue. The supplied query will be used to filter agent notifications.
+ * <p>
+ * Note that in this implementation Agent Discovery is enabled by default. Note too that enableAgentDiscovery()
+ * or disableAgentDiscovery() should be called before addConnection(), as this starts a MessageListener Thread
+ * that could place events on the work queue.
+ *
+ * @param query the query used to filter agent notifications.
+ */
+ public void enableAgentDiscovery(final QmfQuery query)
+ {
+ _discoverAgents = true;
+ _agentQuery = query;
+ }
+
+ /**
+ * Called to disable the async Agent Discovery process enabled by calling enableAgentDiscovery().
+ * <p>
+ * Note that in this implementation Agent Discovery is enabled by default. Note too that enableAgentDiscovery()
+ * or disableAgentDiscovery() should be called before addConnection() as this starts a MessageListener Thread
+ * that could place events on the work queue.
+ */
+ public void disableAgentDiscovery()
+ {
+ _discoverAgents = false;
+ _agentQuery = null;
+ }
+
+ /**
+ * Called to disable asynchronous behaviour such as QMF Events, Agent discovery etc. useful in simple
+ * Use Cases such as getObjects() on the broker. Note that asynchronous behaviour enabled by default.
+ * <p>
+ * Note too that disableEvents() should be called <b>before</b> addConnection() as this
+ * starts the MessageListener Thread and creates the additional queues used for Asynchronous Behaviour.
+ * <p>
+ * This method is <b>not</b> an official method specified in the QMF2 API, however it is a useful extension
+ * as Consoles that only call getObjects() on the broker ManagementAgent is an extremely common scenario.
+ */
+ public void disableEvents()
+ {
+ _disableEvents = true;
+ }
+
+ /**
+ * Return the count of pending WorkItems that can be retrieved.
+ * @return the count of pending WorkItems that can be retrieved.
+ */
+ public int getWorkitemCount()
+ {
+ return _workQueue.size();
+ }
+
+ /**
+ * Obtains the next pending work item - blocking version.
+ * <p>
+ * The blocking getNextWorkitem() can be used without the need for a Notifier as it will block until
+ * a new item gets added to the work queue e.g. the following usage pattern.
+ * <pre>
+ * while ((wi = console.getNextWorkitem()) != null)
+ * {
+ * System.out.println("WorkItem type: " + wi.getType());
+ * }
+ * </pre>
+ * @return the next pending work item, or null if none available.
+ */
+ public WorkItem getNextWorkitem()
+ {
+ return _workQueue.getNextWorkitem();
+ }
+
+ /**
+ * Obtains the next pending work item - balking version.
+ * <p>
+ * The balking getNextWorkitem() is generally used with a Notifier which can be used as a gate to determine
+ * if any work items are available. e.g. the following usage pattern.
+ * <pre>
+ * while (true)
+ * {
+ * notifier.waitForWorkItem(); // Assuming a BlockingNotifier has been used here
+ * System.out.println("WorkItem available, count = " + console.getWorkitemCount());
+ *
+ * WorkItem wi;
+ * while ((wi = console.getNextWorkitem(0)) != null)
+ * {
+ * System.out.println("WorkItem type: " + wi.getType());
+ * }
+ * }
+ * </pre>
+ * Note that it is possible for the getNextWorkitem() loop to retrieve multiple items from the workQueue
+ * and for the Console to add new items as the loop is looping, thus when it finally exits and goes
+ * back to the outer loop notifier.waitForWorkItems() may return immediately as it had been notified
+ * whilst we were in the getNextWorkitem() loop. This will be evident by a getWorkitemCount() of 0
+ * after returning from waitForWorkItem().
+ * <p>
+ * This is the expected behaviour, but illustrates the need to check for nullness of the value returned
+ * by getNextWorkitem(), or alternatively to use getWorkitemCount() to put getNextWorkitem() in a
+ * bounded loop.
+ *
+ * @param timeout the timeout in seconds. If timeout = 0 it returns immediately with either a WorkItem or null
+ * @return the next pending work item, or null if none available.
+ */
+ public WorkItem getNextWorkitem(final long timeout)
+ {
+ return _workQueue.getNextWorkitem(timeout);
+ }
+
+ /**
+ * Releases a WorkItem instance obtained by getNextWorkItem(). Called when the application has finished
+ * processing the WorkItem.
+ */
+ public void releaseWorkitem()
+ {
+ // To be honest I'm not clear what the intent of this method actually is. One thought is that it's here
+ // to support equivalent behaviour to the Python Queue.task_done() which is used by queue consumer threads.
+ // For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing
+ // on the task is complete.
+ //
+ // The problem with that theory is there is no equivalent QMF2 API call that would invoke the
+ // Queue.join() which is used in conjunction with Queue.task_done() to enable a synchronisation gate to
+ // be implemented to wait for completion of all worker thread.
+ //
+ // I'm a bit stumped and there's no obvious Java equivalent on BlockingQueue, so for now this does nothing.
+ }
+
+ /**
+ * Returns a list of all known Agents
+ * <p>
+ * Note that this call is synchronous and non-blocking. It only returns locally cached data and will
+ * not send any messages to the remote agent.
+ *
+ * @return a list of available Agents
+ */
+ public List<Agent> getAgents()
+ {
+ return new ArrayList<Agent>(_agents.values());
+ }
+
+ /**
+ * Return the named Agent, if known.
+ *
+ * @param agentName the name of the Agent to be returned.
+ * <p>
+ * "broker" or "qpidd" may be used as synonyms for the broker Agent name and the method will try to match
+ * agentName against the Agent name, the Agent product name and will also check if the Agent name contains
+ * the agentName String.
+ * <p>
+ * Checking against a partial match is useful because the full Agent name has a UUID representing
+ * the "instance" so it's hard to know the full name without having actually retrieved the Agent.
+ * @return the found Agent instance or null if an Agent of the given name could not be found
+ */
+ public Agent getAgent(final String agentName)
+ {
+ if (agentName == null)
+ {
+ return null;
+ }
+
+ // First we check if the Agent name is one of the aliases of the broker Agent
+ if (_brokerAgentName != null)
+ {
+ if (agentName.equals("broker") || agentName.equals("qpidd") || agentName.equals(_brokerAgentName))
+ {
+ return _agents.get(_brokerAgentName);
+ }
+ }
+
+ for (Agent agent : getAgents())
+ {
+ String product = agent.getProduct();
+ String name = agent.getName();
+ if (agentName.equals(product) || agentName.equals(name) || name.contains(agentName))
+ {
+ return agent;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Return a list of all known Packages.
+ * @return a list of all known Packages.
+ */
+ public List<String> getPackages()
+ {
+ List<String> results = new ArrayList<String>();
+ for (Agent agent : getAgents())
+ {
+ results.addAll(getPackages(agent));
+ }
+ return results;
+ }
+
+ /**
+ * Return a list of Packages for the specified Agent.
+ * @param agent the Agent being queried.
+ * @return a list of Packages for the specified Agent.
+ */
+ public List<String> getPackages(final Agent agent)
+ {
+ return agent.getPackages();
+ }
+
+ /**
+ * Return a List of SchemaClassId for all available Schema.
+ * @return a List of SchemaClassId for all available Schema.
+ */
+ public List<SchemaClassId> getClasses()
+ {
+ List<SchemaClassId> results = new ArrayList<SchemaClassId>();
+ for (Agent agent : getAgents())
+ {
+ results.addAll(getClasses(agent));
+ }
+ return results;
+ }
+
+ /**
+ * Return a list of SchemaClassIds for all available Schema for the specified Agent.
+ * @param agent the Agent being queried
+ * @return a list of SchemaClassIds for all available Schema for the specified Agent.
+ */
+ public List<SchemaClassId> getClasses(final Agent agent)
+ {
+ // First look to see if there are cached results and if there are return those.
+ List<SchemaClassId> results = agent.getClasses();
+ if (results.size() > 0)
+ {
+ return results;
+ }
+
+ String agentName = agent.getName();
+ results = new ArrayList<SchemaClassId>();
+ try
+ {
+ MapMessage request = _syncSession.createMapMessage();
+ request.setJMSReplyTo(_replyAddress);
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_query_request");
+ request.setStringProperty("qpid.subject", agentName);
+
+ // Create a QMF Query for an "SCHEMA_ID" target
+ request.setObject("_what", "SCHEMA_ID");
+ // Wrap request & response in synchronized block in case any other threads invoke a request
+ // it would be somewhat unfortunate if their response got interleaved with ours!!
+ synchronized(this)
+ {
+ _requester.send(request);
+ Message response = _responder.receive(_replyTimeout*1000);
+ if (response == null)
+ {
+ _log.info("No response received in getClasses()");
+ return Collections.emptyList();
+ }
+
+ if (AMQPMessage.isAMQPList(response))
+ {
+ List<Map> mapResults = AMQPMessage.getList(response);
+ for (Map content : mapResults)
+ {
+//new SchemaClassId(content).listValues();
+ results.add(new SchemaClassId(content));
+ }
+ }
+ else if (AMQPMessage.isAMQPMap(response))
+ {
+ // Error responses are returned as MapMessages, though they are being ignored here.
+ //System.out.println("Console.getClasses() no results for " + agentName);
+ //QmfData exception = new QmfData(AMQPMessage.getMap(response));
+ //System.out.println(agentName + " " + exception.getStringValue("error_text"));
+ }
+ else
+ {
+ _log.info("getClasses() Received response message in incorrect format");
+ }
+ }
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in getClasses()", jmse.getMessage());
+ }
+ agent.setClasses(results);
+ return results;
+ }
+
+ /**
+ * Return a list of all available class SchemaClass across all known Agents. If an optional Agent is
+ * provided, restrict the returned schema to those supported by that Agent.
+ * <p>
+ * This call will return cached information if it is available. If not, it will send a query message
+ * to the remote agent and block waiting for a response. The timeout argument specifies the maximum time
+ * to wait for a response from the agent.
+ *
+ * @param schemaClassId the SchemaClassId we wish to return schema information for.
+ */
+ public List<SchemaClass> getSchema(final SchemaClassId schemaClassId)
+ {
+ List<SchemaClass> results = new ArrayList<SchemaClass>();
+ List<Agent> agentList = getAgents();
+ for (Agent agent : agentList)
+ {
+ results.addAll(getSchema(schemaClassId, agent));
+ }
+ return results;
+ }
+
+ /**
+ * Return a list of all available class SchemaClass from a specified Agent.
+ * <p>
+ * This call will return cached information if it is available. If not, it will send a query message
+ * to the remote agent and block waiting for a response. The timeout argument specifies the maximum time
+ * to wait for a response from the agent.
+ *
+ * @param schemaClassId the SchemaClassId we wish to return schema information for.
+ * @param agent the Agent we want to retrieve the schema from
+ */
+ public List<SchemaClass> getSchema(final SchemaClassId schemaClassId, final Agent agent)
+ {
+ // First look to see if there are cached results and if there are return those.
+ List<SchemaClass> results = agent.getSchema(schemaClassId);
+ if (results.size() > 0)
+ {
+ return results;
+ }
+
+ String agentName = agent.getName();
+//System.out.println("getSchema for agent " + agentName);
+ results = new ArrayList<SchemaClass>();
+ try
+ {
+ MapMessage request = _syncSession.createMapMessage();
+ request.setJMSReplyTo(_replyAddress);
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_query_request");
+ request.setStringProperty("qpid.subject", agentName);
+
+ // Create a QMF Query for an "SCHEMA" target
+ request.setObject("_what", "SCHEMA");
+ request.setObject("_schema_id", schemaClassId.mapEncode());
+
+ // Wrap request & response in synchronized block in case any other threads invoke a request
+ // it would be somewhat unfortunate if their response got interleaved with ours!!
+ synchronized(this)
+ {
+ _requester.send(request);
+ Message response = _responder.receive(_replyTimeout*1000);
+ if (response == null)
+ {
+ _log.info("No response received in getSchema()");
+ return Collections.emptyList();
+ }
+
+ if (AMQPMessage.isAMQPList(response))
+ {
+ List<Map> mapResults = AMQPMessage.getList(response);
+ for (Map content : mapResults)
+ {
+ SchemaClass schema = new SchemaObjectClass(content);
+ if (schema.getClassId().getType().equals("_event"))
+ {
+ schema = new SchemaEventClass(content);
+ }
+//schema.listValues();
+ results.add(schema);
+ }
+ }
+ else if (AMQPMessage.isAMQPMap(response))
+ {
+ // Error responses are returned as MapMessages, though they are being ignored here.
+ //System.out.println("Console.getSchema() no results for " + agentName);
+ //QmfData exception = new QmfData(AMQPMessage.getMap(response));
+ //System.out.println(agentName + " " + exception.getStringValue("error_text"));
+ }
+ else
+ {
+ _log.info("getSchema() Received response message in incorrect format");
+ }
+ }
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in getSchema()", jmse.getMessage());
+ }
+ agent.setSchema(schemaClassId, results);
+ return results;
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param className the schema class name we're looking up objects for.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final String className)
+ {
+ return getObjects(new SchemaClassId(className));
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param className the schema class name we're looking up objects for.
+ * @param timeout overrides the default replyTimeout.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final String className, final int timeout)
+ {
+ return getObjects(new SchemaClassId(className), timeout);
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param className the schema class name we're looking up objects for.
+ * @param agentList if this parameter is supplied then the query is sent to only those Agents.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final String className, final List<Agent> agentList)
+ {
+ return getObjects(new SchemaClassId(className), agentList);
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param className the schema class name we're looking up objects for.
+ * @param timeout overrides the default replyTimeout.
+ * @param agentList if this parameter is supplied then the query is sent to only those Agents.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final String className, final int timeout, final List<Agent> agentList)
+ {
+ return getObjects(new SchemaClassId(className), timeout, agentList);
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param packageName the schema package name we're looking up objects for.
+ * @param className the schema class name we're looking up objects for.
+ * @return a List of QMF Objects describing that class
+ */
+ public List<QmfConsoleData> getObjects(final String packageName, final String className)
+ {
+ return getObjects(new SchemaClassId(packageName, className));
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param packageName the schema package name we're looking up objects for.
+ * @param className the schema class name we're looking up objects for.
+ * @param timeout overrides the default replyTimeout.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final String packageName, final String className, final int timeout)
+ {
+ return getObjects(new SchemaClassId(packageName, className), timeout);
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param packageName the schema package name we're looking up objects for.
+ * @param className the schema class name we're looking up objects for.
+ * @param agentList if this parameter is supplied then the query is sent to only those Agents.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final String packageName, final String className, final List<Agent> agentList)
+ {
+ return getObjects(new SchemaClassId(packageName, className), agentList);
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param packageName the schema package name we're looking up objects for.
+ * @param className the schema class name we're looking up objects for.
+ * @param timeout overrides the default replyTimeout.
+ * @param agentList if this parameter is supplied then the query is sent to only those Agents.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final String packageName, final String className,
+ final int timeout, final List<Agent> agentList)
+ {
+ return getObjects(new SchemaClassId(packageName, className), timeout, agentList);
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param query the SchemaClassId or ObjectId we're looking up objects for.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final QmfData query)
+ {
+ return getObjects(query, _replyTimeout, getAgents());
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param query the SchemaClassId or ObjectId we're looking up objects for.
+ * @param timeout overrides the default replyTimeout.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final QmfData query, final int timeout)
+ {
+ return getObjects(query, timeout, getAgents());
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param query the SchemaClassId or ObjectId we're looking up objects for.
+ * @param agentList if this parameter is supplied then the query is sent to only those Agents.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final QmfData query, final List<Agent> agentList)
+ {
+ return getObjects(query, _replyTimeout, agentList);
+ }
+
+ /**
+ * Perform a blocking query for QmfConsoleData objects. Returns a list (possibly empty) of matching objects
+ * This method will block until all known Agents reply, or the timeout expires. Once the timeout expires, all
+ * data retrieved to date is returned.
+ *
+ * @param query the SchemaClassId or ObjectId we're looking up objects for.
+ * @param timeout overrides the default replyTimeout.
+ * @param agentList if this parameter is supplied then the query is sent to only those Agents.
+ * @return a List of QMF Objects describing that class.
+ */
+ public List<QmfConsoleData> getObjects(final QmfData query, final int timeout, final List<Agent> agentList)
+ {
+ List<QmfConsoleData> results = new ArrayList<QmfConsoleData>();
+ for (Agent agent : agentList)
+ {
+ results.addAll(getObjects(agent, query, null, timeout));
+ }
+ return results;
+ }
+
+ /**
+ * Creates a subscription to the agent using the given Query.
+ * <p>
+ * The consoleHandle is an application-provided handle that will accompany each subscription update sent from
+ * the Agent. Subscription updates will appear as SUBSCRIPTION_INDICATION WorkItems on the Console's work queue.
+ *
+ * @param agent the Agent on which to create the subscription.
+ * @param query the Query to perform on the Agent
+ * @param consoleHandle an application-provided handle that will accompany each subscription update sent
+ * from the Agent.
+ */
+ public SubscribeParams createSubscription(final Agent agent, final QmfQuery query,
+ final String consoleHandle) throws QmfException
+ {
+ return createSubscription(agent, query, consoleHandle, null);
+ }
+
+ /**
+ * Creates a subscription to the agent using the given Query.
+ * <p>
+ * The consoleHandle is an application-provided handle that will accompany each subscription update sent from
+ * the Agent. Subscription updates will appear as SUBSCRIPTION_INDICATION WorkItems on the Console's work queue.
+ * <p>
+ * The publishInterval is the requested time interval in seconds on which the Agent should publish updates.
+ * <p>
+ * The lifetime parameter is the requested time interval in seconds for which this subscription should remain in
+ * effect. Both the requested lifetime and publishInterval may be overridden by the Agent, as indicated in the
+ * subscription response.
+ * <p>
+ * This method may be called asynchronously by providing a replyHandle argument. When called
+ * asynchronously, the result of this method call is returned in a SUBSCRIBE_RESPONSE WorkItem with a
+ * handle matching the value of replyHandle.
+ * <p>
+ * Timeout can be used to override the console's default reply timeout.
+ * <p>
+ * When called synchronously, this method returns a SubscribeParams object containing the result of the
+ * subscription request.
+ *
+ * @param agent the Agent on which to create the subscription.
+ * @param query the Query to perform on the Agent
+ * @param consoleHandle an application-provided handle that will accompany each subscription update sent
+ * from the Agent.
+ * @param options a String representation of a Map containing the options in the form
+ * <pre>"{lifetime:&lt;value&gt;, publishInterval:&lt;value&gt;, replyHandle:&lt;value&gt;, timeout:&lt;value&gt;}"</pre>
+ * they are optional and may appear in any order.
+ * <pre>
+ * <b>lifetime</b> the requested time interval in seconds for which this subscription should remain in effect.
+ * <b>publishInterval</b> the requested time interval in seconds on which the Agent should publish updates
+ * <b>replyHandle</b> the correlation handle used to tie asynchronous method requests with responses.
+ * <b>timeout</b> the time to wait for a reply from the Agent.
+ * </pre>
+ */
+ public synchronized SubscribeParams createSubscription(final Agent agent, final QmfQuery query,
+ final String consoleHandle, final String options) throws QmfException
+ {
+ if (consoleHandle == null)
+ {
+ throw new QmfException("Called createSubscription() with null consoleHandle");
+ }
+ if (_subscriptionByHandle.get(consoleHandle) != null)
+ {
+ throw new QmfException("Called createSubscription() with a consoleHandle that is already in use");
+ }
+ if (agent == null)
+ {
+ throw new QmfException("Called createSubscription() with null agent");
+ }
+ if (!agent.isActive())
+ {
+ throw new QmfException("Called createSubscription() with inactive agent");
+ }
+ String agentName = agent.getName();
+
+ // Initialise optional values to defaults;
+ long lifetime = _subscriptionDuration;
+ long publishInterval = 10000;
+ long timeout = _replyTimeout;
+ String replyHandle = null;
+
+ if (options != null)
+ { // We wrap the Map in a QmfData object to avoid potential class cast issues with the parsed options
+ QmfData optMap = new QmfData(new AddressParser(options).map());
+ if (optMap.hasValue("lifetime"))
+ {
+ lifetime = optMap.getLongValue("lifetime");
+ }
+
+ if (optMap.hasValue("publishInterval"))
+ { // Multiply publishInterval by 1000 because the QMF2 protocol spec says interval is
+ // "The request time (in milliseconds) between periodic updates of data in this subscription"
+ publishInterval = 1000*optMap.getLongValue("publishInterval");
+ }
+
+ if (optMap.hasValue("timeout"))
+ {
+ timeout = optMap.getLongValue("timeout");
+ }
+
+ if (optMap.hasValue("replyHandle"))
+ {
+ replyHandle = optMap.getStringValue("replyHandle");
+ }
+ }
+
+ try
+ {
+ MapMessage request = _syncSession.createMapMessage();
+ request.setJMSReplyTo(_asyncReplyAddress); // Deliberately forcing all replies to the _asyncReplyAddress
+ request.setJMSCorrelationID(consoleHandle); // Deliberately using consoleHandle not replyHandle here
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_subscribe_request");
+ request.setStringProperty("qpid.subject", agentName);
+
+ request.setObject("_query", query.mapEncode());
+ request.setObject("_interval", publishInterval);
+ request.setObject("_duration", lifetime);
+
+ SubscriptionManager subscription =
+ new SubscriptionManager(agent, query, consoleHandle, replyHandle, publishInterval, lifetime);
+ _subscriptionByHandle.put(consoleHandle, subscription);
+ _timer.schedule(subscription, 0, publishInterval);
+
+ if (_subscriptionEmulationEnabled && agentName.equals(_brokerAgentName))
+ { // If the Agent is the broker Agent we emulate the Subscription on the Console
+ String subscriptionId = UUID.randomUUID().toString();
+ _subscriptionById.put(subscriptionId, subscription);
+ subscription.setSubscriptionId(subscriptionId);
+ final SubscribeParams params = new SubscribeParams(consoleHandle, subscription.mapEncode());
+ if (replyHandle == null)
+ {
+ return params;
+ }
+ else
+ {
+ final String handle = replyHandle;
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ _eventListener.onEvent(new SubscribeResponseWorkItem(new Handle(handle), params));
+ }
+ };
+ thread.start();
+ }
+ return null;
+ }
+
+ _requester.send(request);
+ if (replyHandle == null)
+ { // If this is an synchronous request get the response
+ subscription.await(timeout*1000);
+ if (subscription.getSubscriptionId() == null)
+ {
+ _log.info("No response received in createSubscription()");
+ throw new QmfException("No response received for Console.createSubscription()");
+ }
+ return new SubscribeParams(consoleHandle, subscription.mapEncode());
+ }
+
+ // If this is an asynchronous request return without waiting for a response
+ return null;
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in createSubscription()", jmse.getMessage());
+ throw new QmfException(jmse.getMessage());
+ }
+ } // end of createSubscription()
+
+ /**
+ * Renews a subscription identified by SubscriptionId.
+ *
+ * @param subscriptionId the ID of the subscription to be refreshed
+ */
+ public void refreshSubscription(final String subscriptionId) throws QmfException
+ {
+ refreshSubscription(subscriptionId, null);
+ }
+
+ /**
+ * Renews a subscription identified by SubscriptionId.
+ * <p>
+ * The Console may request a new subscription duration by providing a requested lifetime. This method may be called
+ * asynchronously by providing a replyHandle argument.
+ * <p>
+ * When called asynchronously, the result of this method call is returned in a SUBSCRIBE_RESPONSE WorkItem.
+ * <p>
+ * Timeout can be used to override the console's default reply timeout.
+ * <p>
+ * When called synchronously, this method returns a class SubscribeParams object containing the result of the
+ * subscription request.
+ *
+ * @param subscriptionId the ID of the subscription to be refreshed
+ * @param options a String representation of a Map containing the options in the form
+ * <pre>"{lifetime:&lt;value&gt;, replyHandle:&lt;value&gt;, timeout:&lt;value&gt;}"</pre>
+ * they are optional and may appear in any order.
+ * <pre>
+ * <b>lifetime</b> requests a new subscription duration.
+ * <b>replyHandle</b> the correlation handle used to tie asynchronous method requests with responses.
+ * <b>timeout</b> the time to wait for a reply from the Agent.
+ * </pre>
+ */
+ public SubscribeParams refreshSubscription(String subscriptionId, final String options) throws QmfException
+ {
+ if (subscriptionId == null)
+ {
+ throw new QmfException("Called refreshSubscription() with null subscriptionId");
+ }
+ SubscriptionManager subscription = _subscriptionById.get(subscriptionId);
+ if (subscription == null)
+ {
+ throw new QmfException("Called refreshSubscription() with invalid subscriptionId");
+ }
+ String consoleHandle = subscription.getConsoleHandle();
+ Agent agent = subscription.getAgent();
+ if (!agent.isActive())
+ {
+ throw new QmfException("Called refreshSubscription() with inactive agent");
+ }
+ String agentName = agent.getName();
+
+ // Initialise optional values to defaults;
+ long lifetime = 0;
+ long timeout = _replyTimeout;
+ String replyHandle = null;
+
+ if (options != null)
+ { // We wrap the Map in a QmfData object to avoid potential class cast issues with the parsed options
+ QmfData optMap = new QmfData(new AddressParser(options).map());
+ if (optMap.hasValue("lifetime"))
+ {
+ lifetime = optMap.getLongValue("lifetime");
+ }
+
+ if (optMap.hasValue("timeout"))
+ {
+ timeout = optMap.getLongValue("timeout");
+ }
+
+ if (optMap.hasValue("replyHandle"))
+ {
+ replyHandle = optMap.getStringValue("replyHandle");
+ }
+ }
+
+ try
+ {
+ Destination destination = (replyHandle == null) ? _replyAddress : _asyncReplyAddress;
+ MapMessage request = _syncSession.createMapMessage();
+ request.setJMSReplyTo(destination);
+ request.setJMSCorrelationID(replyHandle);
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_subscribe_refresh_indication");
+ request.setStringProperty("qpid.subject", agentName);
+
+ request.setObject("_subscription_id", subscriptionId);
+ if (lifetime > 0)
+ {
+ request.setObject("_duration", lifetime);
+ }
+
+ // Wrap request & response in synchronized block in case any other threads invoke a request
+ // it would be somewhat unfortunate if their response got interleaved with ours!!
+ synchronized(this)
+ {
+ if (_subscriptionEmulationEnabled && agentName.equals(_brokerAgentName))
+ { // If the Agent is the broker Agent we emulate the Subscription on the Console
+ subscription.refresh();
+ final SubscribeParams params = new SubscribeParams(consoleHandle, subscription.mapEncode());
+ if (replyHandle == null)
+ {
+ return params;
+ }
+ else
+ {
+ final String handle = replyHandle;
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ _eventListener.onEvent(new SubscribeResponseWorkItem(new Handle(handle), params));
+ }
+ };
+ thread.start();
+ }
+ return null;
+ }
+
+ _requester.send(request);
+ if (replyHandle == null)
+ { // If this is an synchronous request get the response
+ Message response = _responder.receive(timeout*1000);
+ if (response == null)
+ {
+ subscription.cancel();
+ _log.info("No response received in refreshSubscription()");
+ throw new QmfException("No response received for Console.refreshSubscription()");
+ }
+ SubscribeParams result = new SubscribeParams(consoleHandle, AMQPMessage.getMap(response));
+ subscriptionId = result.getSubscriptionId();
+ if (subscriptionId == null)
+ {
+ subscription.cancel();
+ }
+ else
+ {
+ subscription.setDuration(result.getLifetime());
+ subscription.refresh();
+ }
+ return result;
+ }
+ }
+ // If this is an asynchronous request return without waiting for a response
+ return null;
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in refreshSubscription()", jmse.getMessage());
+ throw new QmfException(jmse.getMessage());
+ }
+ } // end of refreshSubscription()
+
+ /**
+ * Terminates the given subscription.
+ *
+ * @param subscriptionId the ID of the subscription to be cancelled
+ */
+ public void cancelSubscription(final String subscriptionId) throws QmfException
+ {
+ if (subscriptionId == null)
+ {
+ throw new QmfException("Called cancelSubscription() with null subscriptionId");
+ }
+ SubscriptionManager subscription = _subscriptionById.get(subscriptionId);
+ if (subscription == null)
+ {
+ throw new QmfException("Called cancelSubscription() with invalid subscriptionId");
+ }
+ String consoleHandle = subscription.getConsoleHandle();
+ Agent agent = subscription.getAgent();
+ if (!agent.isActive())
+ {
+ throw new QmfException("Called cancelSubscription() with inactive agent");
+ }
+ String agentName = agent.getName();
+
+ try
+ {
+ MapMessage request = _syncSession.createMapMessage();
+ request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setStringProperty("method", "request");
+ request.setStringProperty("qmf.opcode", "_subscribe_cancel_indication");
+ request.setStringProperty("qpid.subject", agentName);
+ request.setObject("_subscription_id", subscriptionId);
+
+ synchronized(this)
+ {
+ if (!_subscriptionEmulationEnabled || !agentName.equals(_brokerAgentName))
+ {
+ _requester.send(request);
+ }
+ }
+ subscription.cancel();
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in cancelSubscription()", jmse.getMessage());
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/EventReceivedWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/EventReceivedWorkItem.java
new file mode 100644
index 0000000000..d392871cb6
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/EventReceivedWorkItem.java
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfEvent;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * EVENT_RECEIVED: When an Agent generates a QmfEvent an EVENT_RECEIVED WorkItem is pushed onto the work-queue.
+ * The WorkItem's getParam() call returns a map which contains a reference to the Console Agent
+ * instance that generated the Event and a reference to the QmfEvent itself. The Agent reference
+ * is indexed from the map using the key string "agent, The QmfEvent reference is indexed from
+ * the map using the key string "event". There is no handle associated with this WorkItem.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class EventReceivedWorkItem extends AgentAccessWorkItem
+{
+ /**
+ * Construct a EventReceivedWorkItem. Convenience constructor not in API
+ *
+ * @param agent the Agent used to populate the WorkItem's param
+ * @param event the QmfEvent used to populate the WorkItem's param
+ */
+ public EventReceivedWorkItem(final Agent agent, final QmfEvent event)
+ {
+ super(WorkItemType.EVENT_RECEIVED, null, newParams(agent, event));
+ }
+
+ /**
+ * Return the QmfEvent stored in the params Map.
+ * @return the QmfEvent stored in the params Map.
+ */
+ public QmfEvent getEvent()
+ {
+ Map<String, Object> p = this.<Map<String, Object>>getParams();
+ return (QmfEvent)p.get("event");
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResponseWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResponseWorkItem.java
new file mode 100644
index 0000000000..936af286c2
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResponseWorkItem.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * METHOD_RESPONSE: The METHOD_RESPONSE WorkItem is generated in response to an asynchronous invokeMethod made
+ * by a QmfConsoleData object.
+ *
+ * The getParams() method of a METHOD_RESPONSE WorkItem will return a MethodResult object.
+ * The getHandle() method returns the reply handle provided to the method call.
+ * This handle is merely the handle used for the asynchronous response, it is not associated
+ * with the QmfConsoleData in any other way.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class MethodResponseWorkItem extends WorkItem
+{
+ /**
+ * Construct a MethodResponseWorkItem. Convenience constructor not in API
+ *
+ * @param handle the reply handle used to associate requests and responses
+ * @param params the MethodCallParams used to populate the WorkItem's param
+ */
+ public MethodResponseWorkItem(final Handle handle, final MethodResult params)
+ {
+ super(WorkItemType.METHOD_RESPONSE, handle, params);
+ }
+
+ /**
+ * Return the MethodResult stored in the params.
+ * @return the MethodResult stored in the params.
+ */
+ public MethodResult getMethodResult()
+ {
+ return (MethodResult)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResult.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResult.java
new file mode 100644
index 0000000000..9f8df918fa
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/MethodResult.java
@@ -0,0 +1,151 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfException;
+
+/**
+ * The value(s) returned to the Console when the method call completes are represented by the MethodResult class.
+ * <p>
+ * The MethodResult class indicates whether the method call succeeded or not, and, on success, provides access to all
+ * data returned by the method call.
+ * <p>
+ * Returned data is provided in QmfData map indexed by the name of the parameter. The QmfData map contains only those
+ * parameters that are classified as "output" by the SchemaMethod.
+ * <p?
+ * Should a method call result in a failure, this failure is indicated by the presence of an error object in
+ * the MethodResult. This object is represented by a QmfException object, which contains a description of the
+ * reason for the failure. There are no returned parameters when a method call fails.
+ * <p>
+ * Although not part of the QMF2 API I've made MethodResult extend QmfData so we can directly access the argument
+ * or exception values of the MethodResult object, which tends to neaten up client code.
+ *
+ * @author Fraser Adams
+ */
+public final class MethodResult extends QmfData
+{
+ private QmfData _arguments = null;
+ private QmfData _exception = null;
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+ *
+ * @param m the map used to construct the MethodResult.
+ */
+ @SuppressWarnings("unchecked")
+ public MethodResult(final Map m)
+ {
+ super(m);
+ _exception = this;
+ String opcode = (m == null || !m.containsKey("qmf.opcode")) ? "none" : (String)m.get("qmf.opcode");
+ if (m.size() == 0)
+ { // Valid response from a method returning void
+ _values = m;
+ _arguments = this;
+ _exception = null;
+ }
+ else if (opcode.equals("_method_response"))
+ {
+ Map args = (Map)m.get("_arguments");
+ if (args != null)
+ {
+ _values = args;
+ _arguments = this;
+ _exception = null;
+ }
+ }
+ else if (!opcode.equals("_exception"))
+ {
+ setValue("error_text", "Invalid response received, opcode: " + opcode);
+ }
+ }
+
+ /**
+ * Return true if the method call executed without error.
+ * @return true if the method call executed without error.
+ */
+ public boolean succeeded()
+ {
+ return (_exception == null);
+ }
+
+ /**
+ * Return the QmfData error object if method fails, else null.
+ * @return the QmfData error object if method fails, else null.
+ */
+ public QmfData getException()
+ {
+ return _exception;
+ }
+
+ /**
+ * Return a map of "name"=&lt;value&gt; pairs of all returned arguments.
+ * @return a map of "name"=&lt;value&gt; pairs of all returned arguments.
+ */
+ public QmfData getArguments()
+ {
+ return _arguments;
+ }
+
+ /**
+ * Return value of argument named "name".
+ * @return value of argument named "name".
+ */
+ public Object getArgument(final String name)
+ {
+ if (_arguments == this)
+ {
+ return getValue(name);
+ }
+ return null;
+ }
+
+ /**
+ * Return a QmfException object.
+ * @return a QmfException object.
+ * <p>
+ * If the QmfData exception object contains a String property "error_text" or "message" return a QmfException object
+ * who's message is set to this value else return null;
+ */
+ public QmfException getQmfException()
+ {
+ if (_exception == this)
+ {
+ if (hasValue("error_text"))
+ {
+ return new QmfException(getStringValue("error_text"));
+ }
+
+ if (hasValue("message"))
+ {
+ return new QmfException(getStringValue("message"));
+ }
+ }
+ return null;
+ }
+}
+
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/ObjectUpdateWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/ObjectUpdateWorkItem.java
new file mode 100644
index 0000000000..6b2bfc799e
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/ObjectUpdateWorkItem.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * OBJECT_UPDATE: The OBJECT_UPDATE WorkItem is generated in response to an asynchronous refresh made by
+ * a QmfConsoleData object.
+ *
+ * The getParams() method of an OBJECT_UPDATE WorkItem will return a QmfConsoleData.
+ * The getHandle() method returns the reply handle provided to the refresh() method call.
+ * This handle is merely the handle used for the asynchronous response, it is not associated
+ * with the QmfConsoleData in any other way.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class ObjectUpdateWorkItem extends WorkItem
+{
+ /**
+ * Construct a ObjectUpdateWorkItem. Convenience constructor not in API
+ *
+ * @param handle the reply handle used to associate requests and responses
+ * @param params the QmfConsoleData used to populate the WorkItem's param
+ */
+ public ObjectUpdateWorkItem(final Handle handle, final QmfConsoleData params)
+ {
+ super(WorkItemType.OBJECT_UPDATE, handle, params);
+ }
+
+ /**
+ * Return the QmfConsoleData stored in the params.
+ * @return the QmfConsoleData stored in the params.
+ */
+ public QmfConsoleData getQmfConsoleData()
+ {
+ return (QmfConsoleData)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/QmfConsoleData.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/QmfConsoleData.java
new file mode 100644
index 0000000000..10d764d3d0
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/QmfConsoleData.java
@@ -0,0 +1,277 @@
+/*
+ *
+ * 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.qmf2.console;
+
+// Misc Imports
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfManaged;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+
+/**
+ * Subclass of QmfManaged to provide a Console specific representation of management data.
+ * <p>
+ * The Console application represents a managed data object by the QmfConsoleData class. The Console has "read only"
+ * access to the data values in the data object via this class. The Console can also invoke the methods defined by
+ * the object via this class.
+ * <p>
+ * The actual data stored in this object is cached from the Agent. In order to update the cached values,
+ * the Console invokes the instance's refresh() method.
+ * <p>
+ * Note that the refresh() and invokeMethod() methods require communication with the remote Agent. As such, they
+ * may block. For these two methods, the Console has the option of blocking in the call until the call completes.
+ * Optionally, the Console can receive a notification asynchronously when the operation is complete.
+ *
+ * @author Fraser Adams
+ */
+public class QmfConsoleData extends QmfManaged
+{
+ private final Agent _agent;
+ private long _updateTimestamp;
+ private long _createTimestamp;
+ private long _deleteTimestamp;
+
+ /**
+ * The main constructor, taking a java.util.Map as a parameter. In essence it "deserialises" its state from the Map.
+ *
+ * @param m the map used to construct the SchemaClass.
+ * @param a the Agent that manages this object.
+ */
+ public QmfConsoleData(final Map m, final Agent a)
+ {
+ super(m);
+ long currentTime = System.currentTimeMillis()*1000000l;
+ _updateTimestamp = m.containsKey("_update_ts") ? getLong(m.get("_update_ts")) : currentTime;
+ _createTimestamp = m.containsKey("_create_ts") ? getLong(m.get("_create_ts")) : currentTime;
+ _deleteTimestamp = m.containsKey("_delete_ts") ? getLong(m.get("_delete_ts")) : currentTime;
+ _agent = a;
+ }
+
+ /**
+ * Sets the state of the QmfConsoleData, used as an assignment operator.
+ *
+ * @param m the Map used to initialise the QmfConsoleData
+ */
+ @SuppressWarnings("unchecked")
+ public void initialise(final Map m)
+ {
+ Map<String, Object> values = (Map<String, Object>)m.get("_values");
+ _values = (values == null) ? m : values;
+
+ Map<String, String> subtypes = (Map<String, String>)m.get("_subtypes");
+ _subtypes = subtypes;
+
+ setSchemaClassId(new SchemaClassId((Map)m.get("_schema_id")));
+ setObjectId(new ObjectId((Map)m.get("_object_id")));
+
+ long currentTime = System.currentTimeMillis()*1000000l;
+ _updateTimestamp = m.containsKey("_update_ts") ? getLong(m.get("_update_ts")) : currentTime;
+ _createTimestamp = m.containsKey("_create_ts") ? getLong(m.get("_create_ts")) : currentTime;
+ _deleteTimestamp = m.containsKey("_delete_ts") ? getLong(m.get("_delete_ts")) : currentTime;
+ }
+
+ /**
+ * Sets the state of the QmfConsoleData, used as an assignment operator.
+ *
+ * @param rhs the QmfConsoleData used to initialise the QmfConsoleData
+ */
+ public void initialise(final QmfConsoleData rhs)
+ {
+ _values = rhs._values;
+ _subtypes = rhs._subtypes;
+ setSchemaClassId(rhs.getSchemaClassId());
+ setObjectId(rhs.getObjectId());
+ _updateTimestamp = rhs._updateTimestamp;
+ _createTimestamp = rhs._createTimestamp;
+ _deleteTimestamp = rhs._deleteTimestamp;
+ }
+
+ /**
+ * Return a list of timestamps describing the lifecycle of the object.
+ * @return a list of timestamps describing the lifecycle of the object.
+ * <p>
+ * All timestamps are represented by the AMQP timestamp type recorded in nanoseconds since the epoch.
+ * <pre>
+ * [0] = time of last update from Agent,
+ * [1] = creation timestamp
+ * [2] = deletion timestamp, or zero if not deleted.
+ * </pre>
+ */
+ public final long[] getTimestamps()
+ {
+ long[] timestamps = {_updateTimestamp, _createTimestamp, _deleteTimestamp};
+ return timestamps;
+ }
+
+ /**
+ * Return the creation timestamp.
+ * @return the creation timestamp. Timestamps are recorded in nanoseconds since the epoch.
+ */
+ public final long getCreateTime()
+ {
+ return _createTimestamp;
+ }
+
+ /**
+ * Return the update timestamp.
+ * @return the update timestamp. Timestamps are recorded in nanoseconds since the epoch.
+ */
+ public final long getUpdateTime()
+ {
+ return _updateTimestamp;
+ }
+
+ /**
+ * Return the deletion timestamp, or zero if not deleted.
+ * @return the deletion timestamp, or zero if not deleted. Timestamps are recorded in nanoseconds since the epoch.
+ */
+ public final long getDeleteTime()
+ {
+ return _deleteTimestamp;
+ }
+
+ /**
+ * Return true if deletion timestamp not zero.
+ * @return true if deletion timestamp not zero.
+ */
+ public final boolean isDeleted()
+ {
+ return getDeleteTime() != 0;
+ }
+
+ /**
+ * Request that the Agent updates the value of this object's contents.
+ */
+ public final void refresh() throws QmfException
+ {
+ refresh(-1);
+ }
+
+ /**
+ * Request that the Agent updates the value of this object's contents.
+ *
+ * @param timeout the maximum time in seconds to wait for a response, overrides default replyTimeout.
+ */
+ public final void refresh(final int timeout) throws QmfException
+ {
+ if (_agent == null)
+ {
+ throw new QmfException("QmfConsoleData.refresh() called with null Agent");
+ }
+ QmfConsoleData newContents = _agent.refresh(getObjectId(), null, timeout);
+ if (newContents == null)
+ {
+ _deleteTimestamp = System.currentTimeMillis()*1000000l;
+ }
+ else
+ {
+ // Save the original values of create and delete timestamps as the ManagementAgent doesn't return
+ // these on a call to getObjects(ObjectId);
+ long createTimestamp = _createTimestamp;
+ long deleteTimestamp = _deleteTimestamp;
+ initialise(newContents);
+ _createTimestamp = createTimestamp;
+ _deleteTimestamp = deleteTimestamp;
+ }
+ }
+
+ /**
+ * Request that the Agent updates the value of this object's contents asynchronously.
+ *
+ * @param replyHandle the correlation handle used to tie asynchronous refresh requests with responses.
+ */
+ public final void refresh(final String replyHandle) throws QmfException
+ {
+ if (_agent == null)
+ {
+ throw new QmfException("QmfConsoleData.refresh() called with null Agent");
+ }
+ _agent.refresh(getObjectId(), replyHandle, -1);
+ }
+
+ /**
+ * Invoke the named method on this instance.
+ *
+ * @param name name of the method to invoke.
+ * @param inArgs inArgs an unordered set of key/value pairs comprising the method arguments.
+ * @return the MethodResult.
+ */
+ public final MethodResult invokeMethod(final String name, final QmfData inArgs) throws QmfException
+ {
+ if (_agent == null)
+ {
+ throw new QmfException("QmfConsoleData.invokeMethod() called with null Agent");
+ }
+ return _agent.invokeMethod(getObjectId(), name, inArgs, -1);
+ }
+
+ /**
+ * Invoke the named method on this instance.
+ *
+ * @param name name of the method to invoke.
+ * @param inArgs inArgs an unordered set of key/value pairs comprising the method arguments.
+ * @param timeout the maximum time in seconds to wait for a response, overrides default replyTimeout.
+ * @return the MethodResult.
+ */
+ public final MethodResult invokeMethod(final String name, final QmfData inArgs, final int timeout) throws QmfException
+ {
+ if (_agent == null)
+ {
+ throw new QmfException("QmfConsoleData.invokeMethod() called with null Agent");
+ }
+ return _agent.invokeMethod(getObjectId(), name, inArgs, timeout);
+ }
+
+ /**
+ * Invoke the named method asynchronously on this instance.
+ *
+ * @param name name of the method to invoke.
+ * @param inArgs inArgs an unordered set of key/value pairs comprising the method arguments.
+ * @param replyHandle the correlation handle used to tie asynchronous method requests with responses.
+ */
+ public final void invokeMethod(final String name, final QmfData inArgs, final String replyHandle) throws QmfException
+ {
+ if (_agent == null)
+ {
+ throw new QmfException("QmfConsoleData.invokeMethod() called with null Agent");
+ }
+ _agent.invokeMethod(getObjectId(), name, inArgs, replyHandle);
+ }
+
+ /**
+ * Helper/debug method to list the QMF Object properties and their type.
+ */
+ @Override
+ public void listValues()
+ {
+ super.listValues();
+ System.out.println("_create_ts: " + new Date(getCreateTime()/1000000l));
+ System.out.println("_update_ts: " + new Date(getUpdateTime()/1000000l));
+ System.out.println("_delete_ts: " + new Date(getDeleteTime()/1000000l));
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeIndication.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeIndication.java
new file mode 100644
index 0000000000..8277e3c0e1
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeIndication.java
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.List;
+
+/**
+ * Holds the result of a subscription data indication from the Agent.
+ *
+ * @author Fraser Adams
+ */
+public final class SubscribeIndication
+{
+ private final String _consoleHandle;
+ private final List<QmfConsoleData> _data;
+
+ /**
+ * Construct a SubscribeIndication from a consoleHandle and list of QmfConsoleData.
+ * @param consoleHandle the handle containing the correlation ID.
+ * @param data the list of QmfConsoleData to pass to the Console application.
+ */
+ public SubscribeIndication(final String consoleHandle, final List<QmfConsoleData> data)
+ {
+ _consoleHandle = consoleHandle;
+ _data = data;
+ }
+
+ /**
+ * Return the console handle as passed to the createSubscription() call.
+ * @return the console handle as passed to the createSubscription() call.
+ */
+ public String getConsoleHandle()
+ {
+ return _consoleHandle;
+ }
+
+ /**
+ * Return a list containing all updated QmfData objects associated with the Subscripion.
+ * @return a list containing all updated QmfData objects associated with the Subscripion.
+ */
+ public List<QmfConsoleData> getData()
+ {
+ return _data;
+ }
+}
+
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeParams.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeParams.java
new file mode 100644
index 0000000000..2e15a3153b
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeParams.java
@@ -0,0 +1,130 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfData;
+
+/**
+ * Holds the result of a subscription request made by this Console.
+ * <p>
+ * The SubscriptionId object must be used when the subscription is refreshed or cancelled - it must be passed to the
+ * Console's refreshSubscription() and cancel_subscription() methods. The value of the SubscriptionId does not
+ * change over the lifetime of the subscription.
+ * <p>
+ * The console handle will be provided by the Agent on each data indication event that corresponds to this subscription.
+ * It should not change for the lifetime of the subscription.
+ * <p>
+ * The getHandle() method returns the reply handle provided to the createSubscription() method call. This handle
+ * is merely the handle used for the asynchronous response, it is not associated with the subscription in any other way.
+ * <p>
+ * Once a subscription is created, the Agent that maintains the subscription will periodically issue updates for the
+ * subscribed data. This update will contain the current values of the subscribed data, and will appear as the first
+ * SUBSCRIPTION_INDICATION WorkItem for this subscription.
+ *
+ * @author Fraser Adams
+ */
+public final class SubscribeParams extends QmfData
+{
+ private String _consoleHandle;
+
+ /**
+ * Construct SubscribeParams from a consoleHandle and the Map encoded representation.
+ * @param consoleHandle the console handle as passed to the createSubscription() call.
+ * @param m a Map containing the Map encoded representation of this SubscribeParams.
+ */
+ public SubscribeParams(final String consoleHandle, final Map m)
+ {
+ super(m);
+ _consoleHandle = consoleHandle;
+ }
+
+ /**
+ * If the subscription is successful, this method returns a SubscriptionId object.
+ * Should the subscription fail, this method returns null, and getError() can be used to obtain an
+ * application-specific QmfData error object.
+ *
+ * @return a SubscriptionId object.
+ */
+ public String getSubscriptionId()
+ {
+ if (hasValue("_subscription_id"))
+ {
+ return getStringValue("_subscription_id");
+ }
+ return null;
+ }
+
+ /**
+ * Return the time interval in seconds on which the Agent will publish updates for this subscription.
+ * @return the time interval in seconds on which the Agent will publish updates for this subscription.
+ */
+ public long getPublishInterval()
+ {
+ return getLongValue("_interval");
+ }
+
+ /**
+ * Return the lifetime in seconds for the subscription.
+ * @return the lifetime in seconds for the subscription. The subscription will automatically expire after
+ * this interval if not renewed by the console.
+ */
+ public long getLifetime()
+ {
+ return getLongValue("_duration");
+ }
+
+ /**
+ * Return the QmfData error object if method fails, else null.
+ * @return the QmfData error object if method fails, else null.
+ */
+ public QmfData getError()
+ {
+ if (getSubscriptionId() == null)
+ {
+ return this;
+ }
+ return null;
+ }
+
+ /**
+ * Sets the consoleHandle.
+ * @param consoleHandle the new console handle.
+ */
+ public void setConsoleHandle(final String consoleHandle)
+ {
+ _consoleHandle = consoleHandle;
+ }
+
+ /**
+ * Return the console handle as passed to the createSubscription() call.
+ * @return the console handle as passed to the createSubscription() call.
+ */
+ public String getConsoleHandle()
+ {
+ return _consoleHandle;
+ }
+}
+
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeResponseWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeResponseWorkItem.java
new file mode 100644
index 0000000000..2f84dfcfdd
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscribeResponseWorkItem.java
@@ -0,0 +1,80 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * SUBSCRIBE_RESPONSE: The SUBSCRIBE_RESPONSE WorkItem returns the result of a subscription request made by
+ * this Console. This WorkItem is generated when the Console's createSubscription() is
+ * called in an asychronous manner, rather than pending for the result.
+ *
+ * The getParams() method of a SUBSCRIBE_RESPONSE WorkItem will return an instance of the
+ * SubscribeParams class.
+ *
+ * The SubscriptionId object must be used when the subscription is refreshed or cancelled.
+ * It must be passed to the Console's refresh_subscription() and cancelSubscription() methods.
+ * The value of the SubscriptionId does not change over the lifetime of the subscription.
+ *
+ * The console handle will be provided by the Agent on each data indication event that
+ * corresponds to this subscription. It should not change for the lifetime of the subscription.
+ *
+ * The getHandle() method returns the reply handle provided to the createSubscription()
+ * method call. This handle is merely the handle used for the asynchronous response, it is
+ * not associated with the subscription in any other way.
+ *
+ * Once a subscription is created, the Agent that maintains the subscription will periodically
+ * issue updates for the subscribed data. This update will contain the current values of the
+ * subscribed data, and will appear as the first SUBSCRIPTION_INDICATION WorkItem for this
+ * subscription.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class SubscribeResponseWorkItem extends WorkItem
+{
+ /**
+ * Construct a SubscribeResponseWorkItem. Convenience constructor not in API
+ *
+ * @param handle the reply handle used to associate requests and responses
+ * @param params the SubscribeParams used to populate the WorkItem's param
+ */
+ public SubscribeResponseWorkItem(final Handle handle, final SubscribeParams params)
+ {
+ super(WorkItemType.SUBSCRIBE_RESPONSE, handle, params);
+ }
+
+ /**
+ * Return the SubscribeParams stored in the params.
+ * @return the SubscribeParams stored in the params.
+ */
+ public SubscribeParams getSubscribeParams()
+ {
+ return (SubscribeParams)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionIndicationWorkItem.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionIndicationWorkItem.java
new file mode 100644
index 0000000000..6d1e77595a
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionIndicationWorkItem.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.qmf2.console;
+
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.WorkItem;
+
+/**
+ * Descriptions below are taken from <a href=https://cwiki.apache.org/qpid/qmfv2-api-proposal.html>QMF2 API Proposal</a>
+ * <pre>
+ * SUBSCRIPTION_INDICATION: The SUBSCRIPTION_INDICATION WorkItem signals the arrival of an update to subscribed
+ * data from the Agent.
+ *
+ * The getParams() method of a SUBSCRIPTION_INDICATION WorkItem will return an instance
+ * of the SubscribeIndication class. The getHandle() method returns null.
+ * </pre>
+ * @author Fraser Adams
+ */
+
+public final class SubscriptionIndicationWorkItem extends WorkItem
+{
+ /**
+ * Construct a SubscriptionIndicationWorkItem. Convenience constructor not in API
+ *
+ * @param params the SubscribeParams used to populate the WorkItem's param
+ */
+ public SubscriptionIndicationWorkItem(final SubscribeIndication params)
+ {
+ super(WorkItemType.SUBSCRIPTION_INDICATION, null, params);
+ }
+
+ /**
+ * Return the SubscribeIndication stored in the params.
+ * @return the SubscribeIndication stored in the params.
+ */
+ public SubscribeIndication getSubscribeIndication()
+ {
+ return (SubscribeIndication)getParams();
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionManager.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionManager.java
new file mode 100644
index 0000000000..6e3e9e91b5
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/SubscriptionManager.java
@@ -0,0 +1,255 @@
+/*
+ *
+ * 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.qmf2.console;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Misc Imports
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimerTask;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfQuery;
+
+/**
+ * A SubscriptionManager represents a running Subscription on the Console.
+ * <p>
+ * The main reason we have SubscriptionManagers as TimerTasks is to enable proper cleanup of the references stored in
+ * the subscriptionByHandle and subscriptionById Maps. Ideally these will be cleaned up by a client calling
+ * cancelSubscription but we can't rely on that as the client may forget or the Agent may not respond.
+ * <p>
+ * The SubscriptionManager acts like a client/Console side representation of a Subscription running on an Agent.
+ * As mentioned above its primary purpose is to enable references to Subscriptions maintained by the Console to
+ * be cleaned up should the Subscription time out rather than being cancelled, however as a side effect it is
+ * used to enable emulation of Subscriptions to the broker ManagementAgent, which does not yet natively implement
+ * Subscription.
+ * <p>
+ * To emulate Subscriptions the Console receives the periodic _data indications pushed by the ManagementAgent. The
+ * Console then iterates through Subscriptions referencing the broker Agent and evaluates their queries against
+ * the QmfConsoleData returned by the _data indication. Any QmfConsoleData that match the query are passed to the
+ * client application with the consoleHandle of the matching Subscription.
+ * <p>
+ * The following diagram illustrates the Subscription relationships with the Console and local Agent proxy.
+ * <p>
+ * <img src="doc-files/Subscriptions.png"/>
+ *
+ * @author Fraser Adams
+ */
+public final class SubscriptionManager extends TimerTask
+{
+ private static final Logger _log = LoggerFactory.getLogger(SubscriptionManager.class);
+
+ private final Agent _agent;
+ private long _startTime = System.currentTimeMillis();
+ private String _subscriptionId;
+ private String _consoleHandle;
+ private String _replyHandle;
+ private QmfQuery _query;
+ private long _duration = 0;
+ private long _interval = 0;
+ private boolean _waiting = true;
+
+ /**
+ * Construct a Console side proxy of a Subscription. Primarily to manage references to the Subscription.
+ *
+ * @param agent the Agent from which the Subscription has been requested
+ * @param query the QmfQuery that the Subscription will run
+ * @param consoleHandle the handle that uniquely identifies the Subscription
+ * @param interval the interval between subscription updates
+ * @param duration the duration of the subscription (assuming it doesn't get refreshed)
+ */
+ SubscriptionManager(final Agent agent, final QmfQuery query, final String consoleHandle,
+ final String replyHandle, final long interval, final long duration)
+ {
+ _agent = agent;
+ _query = query;
+ _consoleHandle = consoleHandle;
+ _replyHandle = replyHandle;
+ _interval = interval;
+ _duration = duration;
+ _log.debug("Creating SubscriptionManager {}, on Agent {}",_consoleHandle, _agent.getName());
+ }
+
+ /**
+ * This method gets called periodically by the Timer scheduling this TimerTask.
+ * <p>
+ * First a check is made to see if the Subscription has expired, if it has then it is cancelled.
+ */
+ public void run()
+ {
+ long elapsed = (long)Math.round((System.currentTimeMillis() - _startTime)/1000.0f);
+ if (elapsed >= _duration || !_agent.isActive())
+ {
+ _log.debug("Subscription {} has expired, removing", _subscriptionId);
+ // The Subscription has expired so cancel it
+ cancel();
+ }
+ }
+
+ /**
+ * Causes the current thread to wait until it is signalled or times out.
+ * <p>
+ * This method is primarily used as a means to enable a synchronous call to createSubscription().
+ * For most synchronous calls we simply use the receive() call on the synchronous session, but we can't do that
+ * for createSubscription() as we specifically need to use the replyTo on the asynchronous session as once
+ * subscriptions are created the results are asynchronously pushed. This means we have to get the response to
+ * createSession() on the asynchronous replyTo then signal the (blocked) main thread that the response has
+ * been received.
+ *
+ * @param timeout the maximum time to wait to be signalled.
+ */
+ public synchronized void await(final long timeout)
+ {
+ while (_waiting)
+ {
+ long _startTime = System.currentTimeMillis();
+ try
+ {
+ wait(timeout);
+ }
+ catch (InterruptedException ie)
+ {
+ continue;
+ }
+ // Measure elapsed time to test against spurious wakeups and ensure we really have timed out
+ long elapsedTime = (System.currentTimeMillis() - _startTime);
+ if (elapsedTime >= timeout)
+ {
+ break;
+ }
+ }
+ _waiting = true;
+ }
+
+ /**
+ * Wakes up all waiting threads.
+ */
+ public synchronized void signal()
+ {
+ _waiting = false;
+ notifyAll();
+ }
+
+ /**
+ * Refresh the subscription by zeroing its elapsed time.
+ */
+ public void refresh()
+ {
+ _log.debug("Refreshing Subscription {}", _subscriptionId);
+ _startTime = System.currentTimeMillis();
+ }
+
+ /**
+ * Cancel the Subscription, tidying references up and cancelling the TimerTask.
+ */
+ @Override
+ public boolean cancel()
+ {
+ _log.debug("Cancelling Subscription {}, {}", _consoleHandle, _subscriptionId);
+ _agent.removeSubscription(this);
+ signal(); // Just in case anything is blocking on this Subscription.
+ return super.cancel(); // Cancel the TimerTask
+ }
+
+ /**
+ * Set the SubscriptionId.
+ * @param subscriptionId the new SubscriptionId of this Subscription.
+ */
+ public void setSubscriptionId(final String subscriptionId)
+ {
+ _subscriptionId = subscriptionId;
+ }
+
+ /**
+ * return the SubscriptionId of this Subscription.
+ * @return the SubscriptionId of this Subscription.
+ */
+ public String getSubscriptionId()
+ {
+ return _subscriptionId;
+ }
+
+ /**
+ * Return the consoleHandle of this Subscription.
+ * @return the consoleHandle of this Subscription.
+ */
+ public String getConsoleHandle()
+ {
+ return _consoleHandle;
+ }
+
+ /**
+ * Return the replyHandle of this Subscription.
+ * @return the replyHandle of this Subscription.
+ */
+ public String getReplyHandle()
+ {
+ return _replyHandle;
+ }
+
+ /**
+ * Return the Agent running this Subscription.
+ * @return the Agent running this Subscription.
+ */
+ public Agent getAgent()
+ {
+ return _agent;
+ }
+
+ /**
+ * Set the Subscription lifetime in seconds.
+ *
+ * @param duration the new Subscription lifetime in seconds
+ */
+ public void setDuration(final long duration)
+ {
+ _duration = duration;
+ }
+
+ /**
+ * Return The Subscription's QmfQuery.
+ * @return The Subscription's QmfQuery.
+ */
+ public QmfQuery getQuery()
+ {
+ return _query;
+ }
+
+ /**
+ * Create a Map encoded version.
+ * <p>
+ * When we do a synchronous createSubscription the Subscription itself holds the info needed to populate
+ * the SubscriptionParams result. We encode the info in a Map to pass to the SubscribeParams Constructor
+ */
+ public Map<String, Object> mapEncode()
+ {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("_interval", _interval);
+ map.put("_duration", _duration);
+ map.put("_subscription_id", _subscriptionId);
+ return map;
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Console.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Console.png
new file mode 100644
index 0000000000..cb2a5ee800
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Console.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/QmfEventListenerModel.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/QmfEventListenerModel.png
new file mode 100644
index 0000000000..26a5f71b56
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/QmfEventListenerModel.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Subscriptions.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Subscriptions.png
new file mode 100644
index 0000000000..01772c6d45
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/Subscriptions.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/WorkQueueEventModel.png b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/WorkQueueEventModel.png
new file mode 100644
index 0000000000..fc2a722985
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/console/doc-files/WorkQueueEventModel.png
Binary files differ
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionAudit.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionAudit.java
new file mode 100644
index 0000000000..0ce903c38b
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionAudit.java
@@ -0,0 +1,474 @@
+/*
+ *
+ * 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.qmf2.tools;
+
+// JMS Imports
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+// For DOM parsing the whitelist
+import org.w3c.dom.*;
+import javax.xml.parsers.*;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentRestartedWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import org.apache.qpid.qmf2.util.GetOpt;
+
+/**
+ * Audits connections to one or more Qpid message brokers.
+ * <pre>
+ * Exchange and Queue names are checked against a whitelist and if no match is found an alert is generated.
+ *
+ * If no broker-addr is supplied, ConnectionAudit connects to 'localhost:5672'.
+ *
+ * [broker-addr] syntax:
+ *
+ * [username/password@] hostname
+ * ip-address [:&lt;port&gt;]
+ *
+ * Examples:
+ *
+ * $ ConnectionAudit localhost:5672
+ * $ ConnectionAudit 10.1.1.7:10000
+ * $ ConnectionAudit guest/guest@broker-host:10000
+ *
+ * Options:
+ * -h, --help show this help message and exit
+ * --sasl-mechanism=&lt;mech&gt;
+ * SASL mechanism for authentication (e.g. EXTERNAL,
+ * ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL
+ * automatically picks the most secure available
+ * mechanism - use this option to override.
+ * --whitelist=&lt;whitelist XML document&gt;
+ * The fully qualified name of the whitelist XML file,
+ * default is ./whitelist.xml
+ *
+ * </pre>
+ * An example whitelist is illustrated below, note that in this example the exchanges associated with management
+ * have been whitelisted to remove spurious alerts caused by the temporary management queues.
+ * <pre>
+ *&lt;?xml version="1.0" encoding="UTF-8"?&gt;
+ *&lt;whitelist&gt;
+ * &lt;exchangeWhitelist&gt;
+ * &lt;exchange&gt;qmf.default.topic&lt;/exchange&gt;
+ * &lt;exchange&gt;qmf.default.direct&lt;/exchange&gt;
+ * &lt;exchange&gt;qpid.management&lt;/exchange&gt;
+ * &lt;exchange&gt;amq.direct&lt;/exchange&gt;
+ * &lt;exchange&gt;&lt;/exchange&gt;
+ * &lt;/exchangeWhitelist&gt;
+ * &lt;queueWhitelist&gt;
+ * &lt;queue&gt;testqueue&lt;/queue&gt;
+ * &lt;/queueWhitelist&gt;
+ *&lt;/whitelist&gt;
+ * </pre>
+
+ * @author Fraser Adams
+ */
+public final class ConnectionAudit implements QmfEventListener
+{
+ private static final String _usage =
+ "Usage: ConnectionAudit [options] [broker-addr]...\n";
+
+ private static final String _description =
+ "Audits connections to one or more Qpid message brokers.\n" +
+ "Exchange and Queue names are checked against a whitelist and if no match is found an alert is generated.\n" +
+ "\n" +
+ "If no broker-addr is supplied, ConnectionAudit connects to 'localhost:5672'.\n" +
+ "\n" +
+ "[broker-addr] syntax:\n" +
+ "\n" +
+ "[username/password@] hostname\n" +
+ "ip-address [:<port>]\n" +
+ "\n" +
+ "Examples:\n" +
+ "\n" +
+ "$ ConnectionAudit localhost:5672\n" +
+ "$ ConnectionAudit 10.1.1.7:10000\n" +
+ "$ ConnectionAudit guest/guest@broker-host:10000\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit\n" +
+ " --sasl-mechanism=<mech>\n" +
+ " SASL mechanism for authentication (e.g. EXTERNAL,\n" +
+ " ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL\n" +
+ " automatically picks the most secure available\n" +
+ " mechanism - use this option to override.\n" +
+ " --whitelist=<whitelist XML document>\n" +
+ " The fully qualified name of the whitelist XML file,\n" +
+ " default is ./whitelist.xml\n";
+
+
+ private final String _url;
+ private final String _whitelist;
+ private long _whitelistLastModified = 0;
+ private Console _console;
+
+ // The sets to be used as the whitelists.
+ private Set<String> _exchangeWhitelist = new HashSet<String>();
+ private Set<String> _queueWhitelist = new HashSet<String>();
+
+ /**
+ * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection.
+ * @param url the connection URL.
+ * @param connectionOptions the options String to pass to ConnectionHelper.
+ * @param whitelist the path name of the whitelist XML file.
+ */
+ public ConnectionAudit(final String url, final String connectionOptions, final String whitelist)
+ {
+ System.out.println("Connecting to " + url);
+ _url = url;
+ _whitelist = whitelist;
+ try
+ {
+ Connection connection = ConnectionHelper.createConnection(url, connectionOptions);
+ _console = new Console(this);
+ _console.addConnection(connection);
+ checkExistingSubscriptions();
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println ("QmfException " + qmfe.getMessage() + " caught in ConnectionAudit constructor");
+ }
+ }
+
+ /**
+ * When we start up we need to check any subscriptions that already exist against the whitelist.
+ * Subsequent checks are made only when we receive new subscribe events.
+ */
+ private void checkExistingSubscriptions()
+ {
+ readWhitelist();
+ List<QmfConsoleData> subscriptions = _console.getObjects("org.apache.qpid.broker", "subscription");
+ for (QmfConsoleData subscription : subscriptions)
+ {
+ QmfConsoleData queue = dereference(subscription.getRefValue("queueRef"));
+ QmfConsoleData session = dereference(subscription.getRefValue("sessionRef"));
+ QmfConsoleData connection = dereference(session.getRefValue("connectionRef"));
+
+ String queueName = queue.getStringValue("name");
+ String address = connection.getStringValue("address");
+ String timestamp = new Date(subscription.getCreateTime()/1000000l).toString();
+ validateQueue(queueName, address, timestamp);
+ }
+ }
+
+ /**
+ * Dereferences an ObjectId returning a QmfConsoleData.
+ * @param ref the ObjectId to be dereferenced.
+ * @return the dereferenced QmfConsoleData object or null if the object can't be found.
+ */
+ private QmfConsoleData dereference(final ObjectId ref)
+ {
+ List<QmfConsoleData> data = _console.getObjects(ref);
+ if (data.size() == 1)
+ {
+ return data.get(0);
+ }
+ return null;
+ }
+
+ /**
+ * Looks up the exchange and binding information from the supplied queuename then calls the main validateQueue()
+ * @param queueName the name of the queue that we want to check against the whitelists.
+ * @param exchangeName the name of the exchange that the queue we want to check against the whitelists is bound to.
+ * @param binding the binding associating queue "queueName" with exchange "exchangeName".
+ * @param address the connection address information for the subscription.
+ * @param timestamp the timestamp of the subscription.
+ */
+ private void validateQueue(final String queueName, String exchangeName, final QmfConsoleData binding,
+ final String address, final String timestamp)
+ {
+ if (_exchangeWhitelist.contains(exchangeName))
+ { // Check exchangeName against the exchangeWhitelist and if it's in there we simply return.
+ return;
+ }
+
+ if (_queueWhitelist.contains(queueName))
+ { // Check queueName against the queueWhitelist and if it's in there we simply return.
+ return;
+ }
+
+ if (exchangeName.equals(""))
+ { // Make exchangeName render more prettily if necessary.
+ exchangeName = "''";
+ }
+
+ String bindingKey = binding.getStringValue("bindingKey");
+ Map arguments = (Map)binding.getValue("arguments");
+ if (arguments.isEmpty())
+ {
+ System.out.printf("%s ALERT ConnectionAudit.validateQueue() validation failed for queue: %s with binding[%s] => %s from address: %s with connection timestamp %s\n\n", new Date().toString(), queueName, bindingKey, exchangeName, address, timestamp);
+ }
+ else
+ { // If there are binding arguments then it's a headers exchange so display accordimgly.
+ System.out.printf("%s ALERT ConnectionAudit.validateQueue() validation failed for queue: %s with binding[%s] => %s %s from address: %s with connection timestamp %s\n\n", new Date().toString(), queueName, bindingKey, exchangeName, arguments, address, timestamp);
+ }
+ }
+
+ /**
+ * Looks up the exchange and binding information from the supplied queuename then calls the main validateQueue()
+ * @param queueName the name of the queue that we want to check against the whitelists.
+ * @param address the connection address information for the subscription.
+ * @param timestamp the timestamp of the subscription.
+ */
+ private void validateQueue(final String queueName, final String address, final String timestamp)
+ {
+ ObjectId queueId = null;
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+ for (QmfConsoleData queue : queues)
+ { // We first have to find the ObjectId of the queue called queueName.
+ if (queue.getStringValue("name").equals(queueName))
+ {
+ queueId = queue.getObjectId();
+ break;
+ }
+ }
+
+ if (queueId == null)
+ {
+ System.out.printf("%s ERROR ConnectionAudit.validateQueue() %s reference couldn't be found\n",
+ new Date().toString(), queueName);
+ }
+ else
+ { // If we've got the queue's ObjectId we then find the binding that references it.
+ List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
+ for (QmfConsoleData binding : bindings)
+ {
+ ObjectId queueRef = binding.getRefValue("queueRef");
+ if (queueRef.equals(queueId))
+ { // We've found a binding that matches queue queueName so look up the associated exchange and validate.
+ QmfConsoleData exchange = dereference(binding.getRefValue("exchangeRef"));
+ String exchangeName = exchange.getStringValue("name");
+ validateQueue(queueName, exchangeName, binding, address, timestamp);
+ }
+ }
+ }
+ }
+
+ /**
+ * Handles WorkItems delivered by the Console.
+ * <p>
+ * If we receive an EventReceivedWorkItem check if it is a subscribe event. If it is we check if the whitelist has
+ * changed, and if it has we re-read it. We then extract the queue name, exchange name, binding, connection address
+ * and timestamp and validate with the whitelsist.
+ * <p>
+ * If we receive an AgentRestartedWorkItem we revalidate all subscriptions as it's possible that a client connection
+ * could have been made to the broker before ConnectionAudit has successfully re-established its own connections.
+ * @param wi a QMF2 WorkItem object
+ */
+ public void onEvent(final WorkItem wi)
+ {
+ if (wi instanceof EventReceivedWorkItem)
+ {
+ EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+ QmfEvent event = item.getEvent();
+ String className = event.getSchemaClassId().getClassName();
+ if (className.equals("subscribe"))
+ {
+ readWhitelist();
+ String queueName = event.getStringValue("qName");
+ String address = event.getStringValue("rhost");
+ String timestamp = new Date(event.getTimestamp()/1000000l).toString();
+ validateQueue(queueName, address, timestamp);
+ }
+ }
+ else if (wi instanceof AgentRestartedWorkItem)
+ {
+ checkExistingSubscriptions();
+ }
+ }
+
+ /**
+ * This method first checks if the whitelist file exists, if not it clears the sets used as whitelists
+ * so that no whitelisting is applied. If the whitelist file does exist it is parsed by a DOM parser.
+ * <p>
+ * We look for all exchange and queue elements and populate the respective whitelist sets with their
+ * contents. Note that we check the whitelist file update time to avoid reading it if it hasn't been changed
+ */
+ private void readWhitelist()
+ {
+ File file = new File(_whitelist);
+ if (file.exists())
+ {
+ long mtime = file.lastModified();
+ if (mtime != _whitelistLastModified)
+ {
+ _whitelistLastModified = mtime;
+ _exchangeWhitelist.clear();
+ _queueWhitelist.clear();
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = factory.newDocumentBuilder();
+ Document doc = docBuilder.parse(file);
+
+ Element whitelist = doc.getDocumentElement();
+ if (whitelist.getNodeName().equals("whitelist"))
+ {
+ NodeList children = whitelist.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ Node child = children.item(i);
+ if (child.getNodeName().equals("exchangeWhitelist"))
+ {
+ NodeList exchanges = child.getChildNodes();
+ for (int j = 0; j < exchanges.getLength(); j++)
+ {
+ Node node = exchanges.item(j);
+ if (node.getNodeName().equals("exchange"))
+ {
+ if (node.hasChildNodes())
+ {
+ String exchange = node.getFirstChild().getNodeValue();
+ _exchangeWhitelist.add(exchange);
+ }
+ else
+ {
+ _exchangeWhitelist.add("");
+ }
+ }
+ }
+ }
+ else if (child.getNodeName().equals("queueWhitelist"))
+ {
+ NodeList queues = child.getChildNodes();
+ for (int j = 0; j < queues.getLength(); j++)
+ {
+ Node node = queues.item(j);
+ if (node.getNodeName().equals("queue"))
+ {
+ if (node.hasChildNodes())
+ {
+ String queue = node.getFirstChild().getNodeValue();
+ _queueWhitelist.add(queue);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ { // Failed to parse correctly.
+ System.out.println("Exception " + e + " while reading " + _whitelist);
+ System.out.println(new Date().toString() + " WARN ConnectionAudit.readWhitelist() " +
+ _whitelist + " failed: " + e.getMessage());
+ return;
+ }
+ }
+ }
+ else
+ { // If whitelist file doesn't exist log a warning and clear the whitelists.
+ System.out.println(new Date().toString() + " WARN ConnectionAudit.readWhitelist() " +
+ _whitelist + " doesn't exist");
+ _exchangeWhitelist.clear();
+ _queueWhitelist.clear();
+ }
+ } // End of readWhitelist()
+
+ /**
+ * Runs ConnectionAudit.
+ * @param args the command line arguments.
+ */
+ public static void main(final String[] args)
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ String[] longOpts = {"help", "whitelist=", "sasl-mechanism="};
+ try
+ {
+ String connectionOptions = "{reconnect: true}";
+ String whitelist = "./whitelist.xml";
+ GetOpt getopt = new GetOpt(args, "h", longOpts);
+ List<String[]> optList = getopt.getOptList();
+ String[] cargs = {};
+ cargs = getopt.getEncArgs().toArray(cargs);
+ for (String[] opt : optList)
+ {
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ System.out.println(_usage);
+ System.out.println(_description);
+ System.out.println(_options);
+ System.exit(1);
+ }
+ else if (opt[0].equals("--whitelist"))
+ {
+ whitelist = opt[1];
+ }
+ else if (opt[0].equals("--sasl-mechanism"))
+ {
+ connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
+ }
+ }
+
+ int nargs = cargs.length;
+ if (nargs == 0)
+ {
+ cargs = new String[] {"localhost"};
+ }
+
+ for (String url : cargs)
+ {
+ ConnectionAudit eventPrinter = new ConnectionAudit(url, connectionOptions, whitelist);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(_usage);
+ System.exit(1);
+ }
+
+ try
+ { // Block here
+ Thread.currentThread().join();
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionLogger.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionLogger.java
new file mode 100644
index 0000000000..869d01f40c
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/ConnectionLogger.java
@@ -0,0 +1,383 @@
+/*
+ *
+ * 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.qmf2.tools;
+
+// JMS Imports
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.AgentRestartedWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import org.apache.qpid.qmf2.util.GetOpt;
+
+/**
+ * ConnectionLogger is a QMF2 class used to provide information about connections made to a broker.
+ * <p>
+ * In default mode ConnectionLogger lists the connections made to a broker along with information about sessions
+ * such as whether any subscriptions are associated with the session (if a session has no subscriptions then it's
+ * quite likely to be a "producer only" session, so this knowledge is quite useful).
+ * <p>
+ * In "log queue and binding" mode the information provided is very similar to qpid-config -b queues but with
+ * additional connection related information provided as with default mode.
+ *
+ * <pre>
+ * Usage: ConnectionLogger [options]
+ *
+ * Options:
+ * -h, --help show this help message and exit
+ * -q log queue and binding information for consumer connection
+ * -a &lt;address&gt;, --broker-address=&lt;address&gt;
+ * broker-addr is in the form: [username/password@]
+ * hostname | ip-address [:&lt;port&gt;] ex: localhost,
+ * 10.1.1.7:10000, broker-host:10000,
+ * guest/guest@localhost
+ * --sasl-mechanism=&lt;mech&gt;
+ * SASL mechanism for authentication (e.g. EXTERNAL,
+ * ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL
+ * automatically picks the most secure available
+ * mechanism - use this option to override.
+ * </pre>
+ * @author Fraser Adams
+ */
+public final class ConnectionLogger implements QmfEventListener
+{
+ private static final String _usage =
+ "Usage: ConnectionLogger [options]\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit\n" +
+ " -q log queue and binding information for consumer connections\n" +
+ " -a <address>, --broker-address=<address>\n" +
+ " broker-addr is in the form: [username/password@]\n" +
+ " hostname | ip-address [:<port>] ex: localhost,\n" +
+ " 10.1.1.7:10000, broker-host:10000,\n" +
+ " guest/guest@localhost\n" +
+ " --sasl-mechanism=<mech>\n" +
+ " SASL mechanism for authentication (e.g. EXTERNAL,\n" +
+ " ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL\n" +
+ " automatically picks the most secure available\n" +
+ " mechanism - use this option to override.\n";
+
+ private Console _console;
+ private boolean _logQueues;
+
+ // If any queues get added or deleted we set this to flag that we need to re-log connections on next heartbeat.
+ private boolean _stateChanged = false;
+
+ /**
+ * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection.
+ * @param url the connection URL.
+ * @param connectionOptions the options String to pass to ConnectionHelper.
+ * @param logQueues flags whether queue & binding information is logged as well as connection info.
+ */
+ public ConnectionLogger(final String url, final String connectionOptions, final boolean logQueues)
+ {
+ try
+ {
+ Connection connection = ConnectionHelper.createConnection(url, connectionOptions);
+ _console = new Console(this);
+ _console.addConnection(connection);
+ _logQueues = logQueues;
+ System.out.println("Hit Return to exit");
+ logConnectionInformation();
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println ("QmfException " + qmfe.getMessage() + " caught in ConnectionLogger constructor");
+ }
+ }
+
+ /**
+ * Finds a QmfConsoleData in a List of QMF Objects that matches a given ObjectID
+ *
+ * More or less a direct Java port of findById from qpid-config
+ *
+ * @param items the List of QMF Objects to search
+ * @param id the ObjectId we're searching the List for
+ * @return return the found object as a QmfConsoleData else return null
+ */
+ private QmfConsoleData findById(final List<QmfConsoleData> items, final ObjectId id)
+ {
+ for (QmfConsoleData item : items)
+ {
+ if (item.getObjectId().equals(id))
+ {
+ return item;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * For every queue list the bindings (equivalent of qpid-config -b queues)
+ *
+ * More or less a direct Java port of QueueListRecurse in qpid-config, which handles qpid-config -b queues
+ *
+ * @param ref If ref is null list info about all queues else list info about queue referenced by ObjectID
+ */
+ private void logQueueInformation(final ObjectId ref)
+ {
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+ List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
+ List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
+
+ for (QmfConsoleData queue : queues)
+ {
+ ObjectId queueId = queue.getObjectId();
+
+ if (ref == null || ref.equals(queueId))
+ {
+ System.out.printf(" Queue '%s'\n", queue.getStringValue("name"));
+ System.out.println(" arguments " + (Map)queue.getValue("arguments"));
+
+ for (QmfConsoleData binding : bindings)
+ {
+ ObjectId queueRef = binding.getRefValue("queueRef");
+
+ if (queueRef.equals(queueId))
+ {
+ ObjectId exchangeRef = binding.getRefValue("exchangeRef");
+ QmfConsoleData exchange = findById(exchanges, exchangeRef);
+
+ String exchangeName = "<unknown>";
+ if (exchange != null)
+ {
+ exchangeName = exchange.getStringValue("name");
+ if (exchangeName.equals(""))
+ {
+ exchangeName = "''";
+ }
+ }
+
+ String bindingKey = binding.getStringValue("bindingKey");
+ Map arguments = (Map)binding.getValue("arguments");
+ if (arguments.isEmpty())
+ {
+ System.out.printf(" bind [%s] => %s\n", bindingKey, exchangeName);
+ }
+ else
+ {
+ // If there are binding arguments then it's a headers exchange
+ System.out.printf(" bind [%s] => %s %s\n", bindingKey, exchangeName, arguments);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Logs audit information about each connection made to the broker
+ *
+ * Obtains connection, session and subscription objects and iterates in turn through these comparing
+ * references to find the subscriptions association with sessions and sessions associated with
+ * connections. Ultimately it then uses logQueueInformation to display the queues associated with
+ * each subscription.
+ */
+ private void logConnectionInformation()
+ {
+ System.out.println("\n\n**** ConnectionLogger: Logging current connection information ****");
+
+ List<QmfConsoleData> connections = _console.getObjects("org.apache.qpid.broker", "connection");
+ List<QmfConsoleData> sessions = _console.getObjects("org.apache.qpid.broker", "session");
+ List<QmfConsoleData> subscriptions = _console.getObjects("org.apache.qpid.broker", "subscription");
+
+ for (QmfConsoleData connection : connections)
+ {
+ System.out.printf("\nConnection '%s'\n", connection.getStringValue("address"));
+
+ String[] properties = {"authIdentity","remoteProcessName", "federationLink"};
+ for (String p : properties)
+ {
+ System.out.println(p + ": " + connection.getStringValue(p));
+ }
+
+ System.out.println("createTimestamp: " + new Date(connection.getCreateTime()/1000000l));
+
+ ObjectId connectionId = connection.getObjectId();
+ for (QmfConsoleData session : sessions)
+ { // Iterate through all session objects
+ ObjectId connectionRef = session.getRefValue("connectionRef");
+ if (connectionRef.equals(connectionId))
+ { // But only select sessions that are associated with the connection under consideration.
+ System.out.printf("Session '%s'\n", session.getStringValue("name"));
+ int subscriptionCount = 0;
+ ObjectId sessionId = session.getObjectId();
+ for (QmfConsoleData subscription : subscriptions)
+ { // Iterate through all subscription objects
+ ObjectId sessionRef = subscription.getRefValue("sessionRef");
+ if (sessionRef.equals(sessionId))
+ { // But only select subscriptions that are associated with the session under consideration.
+ subscriptionCount++;
+ ObjectId queueRef = subscription.getRefValue("queueRef");
+ if (_logQueues)
+ {
+ logQueueInformation(queueRef);
+ }
+ }
+ }
+ if (subscriptionCount == 0)
+ {
+ System.out.println(" ** No Subscriptions for this Session - probably a producer only Session **");
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Listener for QMF2 WorkItems
+ * <p>
+ * This method looks for clientConnect or clientDisconnect Events and uses these as a trigger to log the new
+ * connection state when the next Heartbeat occurs.
+ * <p>
+ * There are a couple of reasons for using this approach rather than just calling logConnectionInformation()
+ * as soon as we see the clientConnect or clientDisconnect Event.
+ * <p>
+ * 1. We could potentially have lots of connection Events and redisplaying all of the connections for each
+ * Event is likely to be confusing.
+ * <p>
+ * 2. When a clientConnect Event occurs we don't have all of the informatin that we might need, for example this
+ * application checks the Session and Subscription information and also optionally Queue and Binding information.
+ * Creating Sessions/Subscriptions won't generally occur until some (possibly small, but possibly not) time
+ * after the Connection has been made. The approach taken here reduces spurious assertions that a Session is
+ * probably a "producer only" Session. As one of the use-cases for this tool is to attempt to flag up "producer
+ * only" Sessions we want to try and make it as reliable as possible.
+ *
+ * @param wi a QMF2 WorkItem object
+ */
+ public void onEvent(final WorkItem wi)
+ {
+ if (wi instanceof EventReceivedWorkItem)
+ {
+ EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+ Agent agent = item.getAgent();
+ QmfEvent event = item.getEvent();
+
+ String className = event.getSchemaClassId().getClassName();
+ if (className.equals("clientConnect") ||
+ className.equals("clientDisconnect"))
+ {
+ _stateChanged = true;
+ }
+ }
+ else if (wi instanceof AgentRestartedWorkItem)
+ {
+ _stateChanged = true;
+ }
+ else if (wi instanceof AgentHeartbeatWorkItem)
+ {
+ AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+ Agent agent = item.getAgent();
+
+ if (_stateChanged && agent.getName().contains("qpidd"))
+ {
+ logConnectionInformation();
+ _stateChanged = false;
+ }
+ }
+ }
+
+ /**
+ * Runs ConnectionLogger.
+ * @param args the command line arguments.
+ */
+ public static void main(final String[] args)
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ String[] longOpts = {"help", "broker-address=", "sasl-mechanism="};
+ try
+ {
+ String host = "localhost";
+ String connectionOptions = "{reconnect: true}";
+ boolean logQueues = false;
+
+ GetOpt getopt = new GetOpt(args, "ha:q", longOpts);
+ List<String[]> optList = getopt.getOptList();
+ String[] cargs = {};
+ cargs = getopt.getEncArgs().toArray(cargs);
+
+ for (String[] opt : optList)
+ {
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ System.out.println(_usage);
+ System.out.println(_options);
+ System.exit(1);
+ }
+ else if (opt[0].equals("-a") || opt[0].equals("--broker-address"))
+ {
+ host = opt[1];
+ }
+ else if (opt[0].equals("-q"))
+ {
+ logQueues = true;
+ }
+ else if (opt[0].equals("--sasl-mechanism"))
+ {
+ connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
+ }
+ }
+
+ ConnectionLogger logger = new ConnectionLogger(host, connectionOptions, logQueues);
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(_usage);
+ System.out.println(e.getMessage());
+ System.exit(1);
+ }
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("ConnectionLogger main(): IOException: " + e.getMessage());
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidConfig.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidConfig.java
new file mode 100644
index 0000000000..6c08c471d7
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidConfig.java
@@ -0,0 +1,1564 @@
+/*
+ *
+ * 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.qmf2.tools;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.concurrent.atomic.AtomicInteger;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import org.apache.qpid.qmf2.util.GetOpt;
+
+/**
+ * QpidConfig is a fairly "literal" Java port of the python qpid-config tool.
+ * <p>
+ * It's vaguely pointless, as the python qpid-config is the "canonical" qpid-config :-)
+ * Nonetheless, it's a useful intellectual exercise to illustrate using QMF2 from Java.
+ * <p>
+ * QpidConfig (unlike the python qpid-config) uses pure QMF2 for adding/deleting queues, exchanges & bindings
+ * this provides useful illustration of how to do these things using the ManagementAgent method calls.
+ * <p>
+ * N.B. "create" and "delete" broker ManagementAgent methods were added in Qpid version 0.10, unfortunately these
+ * calls won't work for earlier versions of Qpid.
+ * <pre>
+ * Usage: qpid-config [OPTIONS]
+ * qpid-config [OPTIONS] exchanges [filter-string]
+ * qpid-config [OPTIONS] queues [filter-string]
+ * qpid-config [OPTIONS] add exchange &lt;type&gt; &lt;name&gt; [AddExchangeOptions]
+ * qpid-config [OPTIONS] del exchange &ltname&gt;
+ * qpid-config [OPTIONS] add queue &lt;name&gt; [AddQueueOptions]
+ * qpid-config [OPTIONS] del queue &lt;name&gt; [DelQueueOptions]
+ * qpid-config [OPTIONS] bind &lt;exchange-name&gt; &lt;queue-name&gt; [binding-key]
+ * &lt;for type xml&gt; [-f -|filename]
+ * &lt;for type header&gt; [all|any] k1=v1 [, k2=v2...]
+ * qpid-config [OPTIONS] unbind &lt;exchange-name&gt; &lt;queue-name&gt; [binding-key]
+ *
+ * ADDRESS syntax:
+ *
+ * [username/password@] hostname
+ * ip-address [:&lt;port&gt;]
+ *
+ * Examples:
+ *
+ * $ qpid-config add queue q
+ * $ qpid-config add exchange direct d localhost:5672
+ * $ qpid-config exchanges 10.1.1.7:10000
+ * $ qpid-config queues guest/guest@broker-host:10000
+ *
+ * Add Exchange &lt;type&gt; values:
+ *
+ * direct Direct exchange for point-to-point communication
+ * fanout Fanout exchange for broadcast communication
+ * topic Topic exchange that routes messages using binding keys with wildcards
+ * headers Headers exchange that matches header fields against the binding keys
+ * xml XML Exchange - allows content filtering using an XQuery
+ *
+ *
+ * Queue Limit Actions
+ *
+ * none (default) - Use broker's default policy
+ * reject - Reject enqueued messages
+ * flow-to-disk - Page messages to disk
+ * ring - Replace oldest unacquired message with new
+ * ring-strict - Replace oldest message, reject if oldest is acquired
+ *
+ * Queue Ordering Policies
+ *
+ * fifo (default) - First in, first out
+ * lvq - Last Value Queue ordering, allows queue browsing
+ * lvq-no-browse - Last Value Queue ordering, browsing clients may lose data
+ *
+ * Options:
+ * -h, --help show this help message and exit
+ *
+ * General Options:
+ * -t &lt;secs&gt;, --timeout=&lt;secs&gt;
+ * Maximum time to wait for broker connection (in
+ * seconds)
+ * -b, --bindings Show bindings in queue or exchange list
+ * -a &lt;address&gt;, --broker-addr=&lt;address&gt;
+ * Maximum time to wait for broker connection (in
+ * seconds)
+ * --sasl-mechanism=&lt;mech&gt;
+ * SASL mechanism for authentication (e.g. EXTERNAL,
+ * ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL
+ * automatically picks the most secure available
+ * mechanism - use this option to override.
+ *
+ * Options for Adding Exchanges and Queues:
+ * --alternate-exchange=&lt;aexname&gt;
+ * Name of the alternate-exchange for the new queue or
+ * exchange. Exchanges route messages to the alternate
+ * exchange if they are unable to route them elsewhere.
+ * Queues route messages to the alternate exchange if
+ * they are rejected by a subscriber or orphaned by queue
+ * deletion.
+ * --passive, --dry-run
+ * Do not actually add the exchange or queue, ensure that
+ * all parameters and permissions are correct and would
+ * allow it to be created.
+ * --durable The new queue or exchange is durable.
+ *
+ * Options for Adding Queues:
+ * --cluster-durable The new queue becomes durable if there is only one
+ * functioning cluster node
+ * --file-count=&lt;n&gt; Number of files in queue's persistence journal
+ * --file-size=&lt;n&gt; File size in pages (64Kib/page)
+ * --max-queue-size=&lt;n&gt;
+ * Maximum in-memory queue size as bytes
+ * --max-queue-count=&lt;n&gt;
+ * Maximum in-memory queue size as a number of messages
+ * --limit-policy=&lt;policy&gt;
+ * Action to take when queue limit is reached
+ * --order=&lt;ordering&gt; Queue ordering policy
+ * --generate-queue-events=&lt;n&gt;
+ * If set to 1, every enqueue will generate an event that
+ * can be processed by registered listeners (e.g. for
+ * replication). If set to 2, events will be generated
+ * for enqueues and dequeues.
+ * --flow-stop-size=&lt;n&gt;
+ * Turn on sender flow control when the number of queued
+ * bytes exceeds this value.
+ * --flow-resume-size=&lt;n&gt;
+ * Turn off sender flow control when the number of queued
+ * bytes drops below this value.
+ * --flow-stop-count=&lt;n&gt;
+ * Turn on sender flow control when the number of queued
+ * messages exceeds this value.
+ * --flow-resume-count=&lt;n&gt;
+ * Turn off sender flow control when the number of queued
+ * messages drops below this value.
+ * --argument=&lt;NAME=VALUE&gt;
+ * Specify a key-value pair to add to queue arguments
+ *
+ * Options for Adding Exchanges:
+ * --sequence Exchange will insert a 'qpid.msg_sequence' field in
+ * the message header
+ * --ive Exchange will behave as an 'initial-value-exchange',
+ * keeping a reference to the last message forwarded and
+ * enqueuing that message to newly bound queues.
+ *
+ * Options for Deleting Queues:
+ * --force Force delete of queue even if it's currently used or
+ * it's not empty
+ * --force-if-not-empty
+ * Force delete of queue even if it's not empty
+ * --force-if-not-used
+ * Force delete of queue even if it's currently used
+ *
+ * Options for Declaring Bindings:
+ * -f &lt;file.xq&gt;, --file=&lt;file.xq&gt;
+ * For XML Exchange bindings - specifies the name of a
+ * file containing an XQuery.
+ *
+ * </pre>
+ * @author Fraser Adams
+ */
+public final class QpidConfig
+{
+ private static final String _usage =
+ "Usage: qpid-config [OPTIONS]\n" +
+ " qpid-config [OPTIONS] exchanges [filter-string]\n" +
+ " qpid-config [OPTIONS] queues [filter-string]\n" +
+ " qpid-config [OPTIONS] add exchange <type> <name> [AddExchangeOptions]\n" +
+ " qpid-config [OPTIONS] del exchange <name>\n" +
+ " qpid-config [OPTIONS] add queue <name> [AddQueueOptions]\n" +
+ " qpid-config [OPTIONS] del queue <name> [DelQueueOptions]\n" +
+ " qpid-config [OPTIONS] bind <exchange-name> <queue-name> [binding-key]\n" +
+ " <for type xml> [-f -|filename]\n" +
+ " <for type header> [all|any] k1=v1 [, k2=v2...]\n" +
+ " qpid-config [OPTIONS] unbind <exchange-name> <queue-name> [binding-key]\n";
+
+ private static final String _description =
+ "ADDRESS syntax:\n" +
+ "\n" +
+ " [username/password@] hostname\n" +
+ " ip-address [:<port>]\n" +
+ "\n" +
+ "Examples:\n" +
+ "\n" +
+ "$ qpid-config add queue q\n" +
+ "$ qpid-config add exchange direct d localhost:5672\n" +
+ "$ qpid-config exchanges 10.1.1.7:10000\n" +
+ "$ qpid-config queues guest/guest@broker-host:10000\n" +
+ "\n" +
+ "Add Exchange <type> values:\n" +
+ "\n" +
+ " direct Direct exchange for point-to-point communication\n" +
+ " fanout Fanout exchange for broadcast communication\n" +
+ " topic Topic exchange that routes messages using binding keys with wildcards\n" +
+ " headers Headers exchange that matches header fields against the binding keys\n" +
+ " xml XML Exchange - allows content filtering using an XQuery\n" +
+ "\n" +
+ "\n" +
+ "Queue Limit Actions\n" +
+ "\n" +
+ " none (default) - Use broker's default policy\n" +
+ " reject - Reject enqueued messages\n" +
+ " flow-to-disk - Page messages to disk\n" +
+ " ring - Replace oldest unacquired message with new\n" +
+ " ring-strict - Replace oldest message, reject if oldest is acquired\n" +
+ "\n" +
+ "Queue Ordering Policies\n" +
+ "\n" +
+ " fifo (default) - First in, first out\n" +
+ " lvq - Last Value Queue ordering, allows queue browsing\n" +
+ " lvq-no-browse - Last Value Queue ordering, browsing clients may lose data\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit\n" +
+ "\n" +
+ " General Options:\n" +
+ " -t <secs>, --timeout=<secs>\n" +
+ " Maximum time to wait for broker connection (in\n" +
+ " seconds)\n" +
+ " -b, --bindings Show bindings in queue or exchange list\n" +
+ " -a <address>, --broker-addr=<address>\n" +
+ " Maximum time to wait for broker connection (in\n" +
+ " seconds)\n" +
+ " --sasl-mechanism=<mech>\n" +
+ " SASL mechanism for authentication (e.g. EXTERNAL,\n" +
+ " ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL\n" +
+ " automatically picks the most secure available\n" +
+ " mechanism - use this option to override.\n" +
+ "\n" +
+ " Options for Adding Exchanges and Queues:\n" +
+ " --alternate-exchange=<aexname>\n" +
+ " Name of the alternate-exchange for the new queue or\n" +
+ " exchange. Exchanges route messages to the alternate\n" +
+ " exchange if they are unable to route them elsewhere.\n" +
+ " Queues route messages to the alternate exchange if\n" +
+ " they are rejected by a subscriber or orphaned by queue\n" +
+ " deletion.\n" +
+ " --passive, --dry-run\n" +
+ " Do not actually add the exchange or queue, ensure that\n" +
+ " all parameters and permissions are correct and would\n" +
+ " allow it to be created.\n" +
+ " --durable The new queue or exchange is durable.\n" +
+ "\n" +
+ " Options for Adding Queues:\n" +
+ " --cluster-durable The new queue becomes durable if there is only one\n" +
+ " functioning cluster node\n" +
+ " --file-count=<n> Number of files in queue's persistence journal\n" +
+ " --file-size=<n> File size in pages (64Kib/page)\n" +
+ " --max-queue-size=<n>\n" +
+ " Maximum in-memory queue size as bytes\n" +
+ " --max-queue-count=<n>\n" +
+ " Maximum in-memory queue size as a number of messages\n" +
+ " --limit-policy=<policy>\n" +
+ " Action to take when queue limit is reached\n" +
+ " --order=<ordering> Queue ordering policy\n" +
+ " --generate-queue-events=<n>\n" +
+ " If set to 1, every enqueue will generate an event that\n" +
+ " can be processed by registered listeners (e.g. for\n" +
+ " replication). If set to 2, events will be generated\n" +
+ " for enqueues and dequeues.\n" +
+ " --flow-stop-size=<n>\n" +
+ " Turn on sender flow control when the number of queued\n" +
+ " bytes exceeds this value.\n" +
+ " --flow-resume-size=<n>\n" +
+ " Turn off sender flow control when the number of queued\n" +
+ " bytes drops below this value.\n" +
+ " --flow-stop-count=<n>\n" +
+ " Turn on sender flow control when the number of queued\n" +
+ " messages exceeds this value.\n" +
+ " --flow-resume-count=<n>\n" +
+ " Turn off sender flow control when the number of queued\n" +
+ " messages drops below this value.\n" +
+ " --argument=<NAME=VALUE>\n" +
+ " Specify a key-value pair to add to queue arguments\n" +
+ "\n" +
+ " Options for Adding Exchanges:\n" +
+ " --sequence Exchange will insert a 'qpid.msg_sequence' field in\n" +
+ " the message header\n" +
+ " --ive Exchange will behave as an 'initial-value-exchange',\n" +
+ " keeping a reference to the last message forwarded and\n" +
+ " enqueuing that message to newly bound queues.\n" +
+ "\n" +
+ " Options for Deleting Queues:\n" +
+ " --force Force delete of queue even if it's currently used or\n" +
+ " it's not empty\n" +
+ " --force-if-not-empty\n" +
+ " Force delete of queue even if it's not empty\n" +
+ " --force-if-not-used\n" +
+ " Force delete of queue even if it's currently used\n" +
+ "\n" +
+ " Options for Declaring Bindings:\n" +
+ " -f <file.xq>, --file=<file.xq>\n" +
+ " For XML Exchange bindings - specifies the name of a\n" +
+ " file containing an XQuery.\n";
+
+ private Console _console;
+ private QmfConsoleData _broker;
+
+ private boolean _recursive = false;
+ private String _host = "localhost";
+ private int _connTimeout = 10;
+ private String _altExchange = null;
+ private boolean _passive = false;
+ private boolean _durable = false;
+ private boolean _clusterDurable = false;
+ private boolean _ifEmpty = true;
+ private boolean _ifUnused = true;
+ private long _fileCount = 8;
+ private long _fileSize = 24;
+ private long _maxQueueSize = 0;
+ private long _maxQueueCount = 0;
+ private String _limitPolicy = "none";
+ private String _order = "fifo";
+ private boolean _msgSequence = false;
+ private boolean _ive = false;
+ private long _eventGeneration = 0;
+ private String _file = null;
+
+ // New to Qpid 0.10 qpid-config
+ private String _saslMechanism = null;
+ private long _flowStopCount = 0;
+ private long _flowResumeCount = 0;
+ private long _flowStopSize = 0;
+ private long _flowResumeSize = 0;
+ private List<String> extraArguments = new ArrayList<String>();
+
+ private static final String FILECOUNT = "qpid.file_count";
+ private static final String FILESIZE = "qpid.file_size";
+ private static final String MAX_QUEUE_SIZE = "qpid.max_size";
+ private static final String MAX_QUEUE_COUNT = "qpid.max_count";
+ private static final String POLICY_TYPE = "qpid.policy_type";
+ private static final String CLUSTER_DURABLE = "qpid.persist_last_node";
+ private static final String LVQ = "qpid.last_value_queue";
+ private static final String LVQNB = "qpid.last_value_queue_no_browse";
+ private static final String MSG_SEQUENCE = "qpid.msg_sequence";
+ private static final String IVE = "qpid.ive";
+ private static final String QUEUE_EVENT_GENERATION = "qpid.queue_event_generation";
+ private static final String FLOW_STOP_COUNT = "qpid.flow_stop_count";
+ private static final String FLOW_RESUME_COUNT = "qpid.flow_resume_count";
+ private static final String FLOW_STOP_SIZE = "qpid.flow_stop_size";
+ private static final String FLOW_RESUME_SIZE = "qpid.flow_resume_size";
+
+ // There are various arguments to declare that have specific program options in this utility.
+ // However there is now a generic mechanism for passing arguments as well. The SPECIAL_ARGS
+ // set contains the arguments for which there are specific program options defined i.e. the
+ // arguments for which there is special processing on add and list.
+ private static HashSet<String> SPECIAL_ARGS = new HashSet<String>();
+
+ static
+ {
+ SPECIAL_ARGS.add(FILECOUNT);
+ SPECIAL_ARGS.add(FILESIZE);
+ SPECIAL_ARGS.add(MAX_QUEUE_SIZE);
+ SPECIAL_ARGS.add(MAX_QUEUE_COUNT);
+ SPECIAL_ARGS.add(POLICY_TYPE);
+ SPECIAL_ARGS.add(CLUSTER_DURABLE);
+ SPECIAL_ARGS.add(LVQ);
+ SPECIAL_ARGS.add(LVQNB);
+ SPECIAL_ARGS.add(MSG_SEQUENCE);
+ SPECIAL_ARGS.add(IVE);
+ SPECIAL_ARGS.add(QUEUE_EVENT_GENERATION);
+ SPECIAL_ARGS.add(FLOW_STOP_COUNT);
+ SPECIAL_ARGS.add(FLOW_RESUME_COUNT);
+ SPECIAL_ARGS.add(FLOW_STOP_SIZE);
+ SPECIAL_ARGS.add(FLOW_RESUME_SIZE);
+ }
+
+ /**
+ * Display long-form QpidConfig usage.
+ */
+ private void usage()
+ {
+ System.out.println(_usage);
+ System.exit(1);
+ }
+
+ /**
+ * Display QpidConfig options.
+ */
+ private void options()
+ {
+ System.out.println(_usage);
+ System.out.println(_description);
+ System.out.println(_options);
+ System.exit(1);
+ }
+
+ /**
+ * Finds a QmfConsoleData instance in a List of QMF Objects that matches a given ObjectID.
+ *
+ * More or less a direct Java port of findById from qpid-config.
+ *
+ * @param items the List of QMF Objects to search.
+ * @param id the ObjectId we're searching the List for.
+ * @return return the found object as a QmfConsoleData else return null.
+ */
+ private QmfConsoleData findById(final List<QmfConsoleData> items, final ObjectId id)
+ {
+ for (QmfConsoleData item : items)
+ {
+ if (item.getObjectId().equals(id))
+ {
+ return item;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Provide a basic overview of the number and type of queues and exchanges.
+ */
+ private void overview()
+ {
+ List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+
+ System.out.printf("Total Exchanges: %d\n", exchanges.size());
+
+ Map<String, AtomicInteger> etype = new HashMap<String, AtomicInteger>();
+ for (QmfConsoleData exchange : exchanges)
+ {
+ String exchangeType = exchange.getStringValue("type");
+ AtomicInteger n = etype.get(exchangeType);
+ if (n == null)
+ {
+ etype.put(exchangeType, new AtomicInteger(1));
+ }
+ else
+ {
+ n.getAndIncrement();
+ }
+ }
+
+ for (Map.Entry<String, AtomicInteger> entry : etype.entrySet())
+ {
+ System.out.printf("%15s: %s\n", entry.getKey(), entry.getValue());
+ }
+
+ System.out.println();
+ System.out.printf(" Total Queues: %d\n", queues.size());
+
+ int durable = 0;
+ for (QmfConsoleData queue : queues)
+ {
+ boolean isDurable = queue.getBooleanValue("durable");
+ if (isDurable)
+ {
+ durable++;
+ }
+ }
+
+ System.out.printf(" durable: %d\n", durable);
+ System.out.printf(" non-durable: %d\n", queues.size() - durable);
+ }
+
+ /**
+ * For every exchange list detailed info (equivalent of qpid-config exchanges).
+ *
+ * More or less a direct Java port of ExchangeList in qpid-config, which handles qpid-config exchanges.
+ *
+ * @param filter specifies the exchange name to display info for, if set to "" displays info for every exchange.
+ */
+ private void exchangeList(final String filter)
+ {
+ List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
+
+ String caption1 = "Type ";
+ String caption2 = "Exchange Name";
+ int maxNameLen = caption2.length();
+
+ for (QmfConsoleData exchange : exchanges)
+ {
+ String name = exchange.getStringValue("name");
+ if (filter.equals("") || filter.equals(name))
+ {
+ if (name.length() > maxNameLen)
+ {
+ maxNameLen = name.length();
+ }
+ }
+ }
+
+ System.out.printf("%s%-" + maxNameLen + "s Attributes\n", caption1, caption2);
+
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < (((maxNameLen + caption1.length()) / 5) + 5); i++)
+ {
+ buf.append("=====");
+ }
+ String line = buf.toString();
+ System.out.println(line);
+
+ for (QmfConsoleData exchange : exchanges)
+ {
+ String name = exchange.getStringValue("name");
+ if (filter.equals("") || filter.equals(name))
+ {
+ System.out.printf("%-10s%-" + maxNameLen + "s ", exchange.getStringValue("type"), name);
+ Map args = (Map)exchange.getValue("arguments");
+
+ if (exchange.getBooleanValue("durable"))
+ {
+ System.out.printf("--durable ");
+ }
+
+ if (args.containsKey(MSG_SEQUENCE) && QmfData.getLong(args.get(MSG_SEQUENCE)) == 1)
+ {
+ System.out.printf("--sequence ");
+ }
+
+ if (args.containsKey(IVE) && QmfData.getLong(args.get(IVE)) == 1)
+ {
+ System.out.printf("--ive ");
+ }
+
+ if (exchange.hasValue("altExchange"))
+ {
+ ObjectId altExchangeRef = exchange.getRefValue("altExchange");
+ QmfConsoleData altExchange = findById(exchanges, altExchangeRef);
+ if (altExchange != null)
+ {
+ System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name"));
+ }
+ }
+
+ System.out.println();
+ }
+ }
+ }
+
+ /**
+ * For every exchange list the bindings (equivalent of qpid-config -b exchanges).
+ *
+ * More or less a direct Java port of ExchangeListRecurse in qpid-config, which handles qpid-config -b exchanges.
+ *
+ * @param filter specifies the exchange name to display info for, if set to "" displays info for every exchange.
+ */
+ private void exchangeListRecurse(final String filter)
+ {
+ List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
+ List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+
+ for (QmfConsoleData exchange : exchanges)
+ {
+ ObjectId exchangeId = exchange.getObjectId();
+ String name = exchange.getStringValue("name");
+
+ if (filter.equals("") || filter.equals(name))
+ {
+ System.out.printf("Exchange '%s' (%s)\n", name, exchange.getStringValue("type"));
+ for (QmfConsoleData binding : bindings)
+ {
+ ObjectId exchangeRef = binding.getRefValue("exchangeRef");
+
+ if (exchangeRef.equals(exchangeId))
+ {
+ ObjectId queueRef = binding.getRefValue("queueRef");
+ QmfConsoleData queue = findById(queues, queueRef);
+
+ String queueName = "<unknown>";
+ if (queue != null)
+ {
+ queueName = queue.getStringValue("name");
+ if (queueName.equals(""))
+ {
+ queueName = "''";
+ }
+ }
+
+ String bindingKey = binding.getStringValue("bindingKey");
+ Map arguments = (Map)binding.getValue("arguments");
+ if (arguments.isEmpty())
+ {
+ System.out.printf(" bind [%s] => %s\n", bindingKey, queueName);
+ }
+ else
+ {
+ // If there are binding arguments then it's a headers exchange
+ System.out.printf(" bind [%s] => %s %s\n", bindingKey, queueName, arguments);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * For every queue list detailed info (equivalent of qpid-config queues).
+ *
+ * More or less a direct Java port of QueueList in qpid-config, which handles qpid-config queues.
+ *
+ * @param filter specifies the queue name to display info for, if set to "" displays info for every queue.
+ */
+ private void queueList(final String filter)
+ {
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+
+ String caption = "Queue Name";
+ int maxNameLen = caption.length();
+
+ for (QmfConsoleData queue : queues)
+ {
+ String name = queue.getStringValue("name");
+ if (filter.equals("") || filter.equals(name))
+ {
+ if (name.length() > maxNameLen)
+ {
+ maxNameLen = name.length();
+ }
+ }
+ }
+
+ System.out.printf("%-" + maxNameLen + "s Attributes\n", caption);
+
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < ((maxNameLen / 5) + 5); i++)
+ {
+ buf.append("=====");
+ }
+ String line = buf.toString();
+ System.out.println(line);
+
+ for (QmfConsoleData queue : queues)
+ {
+ String name = queue.getStringValue("name");
+ if (filter.equals("") || filter.equals(name))
+ {
+ System.out.printf("%-" + maxNameLen + "s ", name);
+ Map<String, Object> args = queue.<Map<String, Object>>getValue("arguments");
+/*System.out.println(args);
+for (Map.Entry<String, Object> entry : args.entrySet()) {
+ System.out.println(entry.getKey() + " " + entry.getValue().getClass().getCanonicalName());
+}*/
+ if (queue.getBooleanValue("durable"))
+ {
+ System.out.printf("--durable ");
+ }
+
+ if (args.containsKey(CLUSTER_DURABLE) && QmfData.getLong(args.get(CLUSTER_DURABLE)) == 1)
+ {
+ System.out.printf("--cluster-durable ");
+ }
+
+ if (queue.getBooleanValue("autoDelete"))
+ {
+ System.out.printf("auto-del ");
+ }
+
+ if (queue.getBooleanValue("exclusive"))
+ {
+ System.out.printf("excl ");
+ }
+
+ if (args.containsKey(FILESIZE))
+ {
+ System.out.printf("--file-size=%d ", QmfData.getLong(args.get(FILESIZE)));
+ }
+
+ if (args.containsKey(FILECOUNT))
+ {
+ System.out.printf("--file-count=%d ", QmfData.getLong(args.get(FILECOUNT)));
+ }
+
+ if (args.containsKey(MAX_QUEUE_SIZE))
+ {
+ System.out.printf("--max-queue-size=%d ", QmfData.getLong(args.get(MAX_QUEUE_SIZE)));
+ }
+
+ if (args.containsKey(MAX_QUEUE_COUNT))
+ {
+ System.out.printf("--max-queue-count=%d ", QmfData.getLong(args.get(MAX_QUEUE_COUNT)));
+ }
+
+ if (args.containsKey(POLICY_TYPE))
+ {
+ System.out.printf("--limit-policy=%s ", (QmfData.getString(args.get(POLICY_TYPE))).replace("_", "-"));
+ }
+
+ if (args.containsKey(LVQ) && QmfData.getLong(args.get(LVQ)) == 1)
+ {
+ System.out.printf("--order lvq ");
+ }
+
+ if (args.containsKey(LVQNB) && QmfData.getLong(args.get(LVQNB)) == 1)
+ {
+ System.out.printf("--order lvq-no-browse ");
+ }
+
+ if (args.containsKey(QUEUE_EVENT_GENERATION))
+ {
+ System.out.printf("--generate-queue-events=%d ", QmfData.getLong(args.get(QUEUE_EVENT_GENERATION)));
+ }
+
+ if (queue.hasValue("altExchange"))
+ {
+ ObjectId altExchangeRef = queue.getRefValue("altExchange");
+ List<QmfConsoleData> altExchanges = _console.getObjects(altExchangeRef);
+ if (altExchanges.size() == 1)
+ {
+ QmfConsoleData altExchange = altExchanges.get(0);
+ System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name"));
+ }
+ }
+
+ if (args.containsKey(FLOW_STOP_SIZE))
+ {
+ System.out.printf("--flow-stop-size=%d ", QmfData.getLong(args.get(FLOW_STOP_SIZE)));
+ }
+
+ if (args.containsKey(FLOW_RESUME_SIZE))
+ {
+ System.out.printf("--flow-resume-size=%d ", QmfData.getLong(args.get(FLOW_RESUME_SIZE)));
+ }
+
+ if (args.containsKey(FLOW_STOP_COUNT))
+ {
+ System.out.printf("--flow-stop-count=%d ", QmfData.getLong(args.get(FLOW_STOP_COUNT)));
+ }
+
+ if (args.containsKey(FLOW_RESUME_COUNT))
+ {
+ System.out.printf("--flow-resume-count=%d ", QmfData.getLong(args.get(FLOW_RESUME_COUNT)));
+ }
+
+ for (Map.Entry<String, Object> entry : args.entrySet())
+ { // Display generic queue arguments
+ if (!SPECIAL_ARGS.contains(entry.getKey()))
+ {
+ System.out.printf("--argument %s=%s ", entry.getKey(), entry.getValue());
+ }
+ }
+
+ System.out.println();
+ }
+ }
+ }
+
+ /**
+ * For every queue list the bindings (equivalent of qpid-config -b queues).
+ *
+ * More or less a direct Java port of QueueListRecurse in qpid-config, which handles qpid-config -b queues.
+ *
+ * @param filter specifies the queue name to display info for, if set to "" displays info for every queue.
+ */
+ private void queueListRecurse(final String filter)
+ {
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+ List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
+ List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
+
+ for (QmfConsoleData queue : queues)
+ {
+ ObjectId queueId = queue.getObjectId();
+ String name = queue.getStringValue("name");
+
+ if (filter.equals("") || filter.equals(name))
+ {
+ System.out.printf("Queue '%s'\n", name);
+
+ for (QmfConsoleData binding : bindings)
+ {
+ ObjectId queueRef = binding.getRefValue("queueRef");
+
+ if (queueRef.equals(queueId))
+ {
+ ObjectId exchangeRef = binding.getRefValue("exchangeRef");
+ QmfConsoleData exchange = findById(exchanges, exchangeRef);
+
+ String exchangeName = "<unknown>";
+ if (exchange != null)
+ {
+ exchangeName = exchange.getStringValue("name");
+ if (exchangeName.equals(""))
+ {
+ exchangeName = "''";
+ }
+ }
+
+ String bindingKey = binding.getStringValue("bindingKey");
+ Map arguments = (Map)binding.getValue("arguments");
+ if (arguments.isEmpty())
+ {
+ System.out.printf(" bind [%s] => %s\n", bindingKey, exchangeName);
+ }
+ else
+ {
+ // If there are binding arguments then it's a headers exchange
+ System.out.printf(" bind [%s] => %s %s\n", bindingKey, exchangeName, arguments);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Add an exchange using the QMF "create" method.
+ * @param args the exchange type is the first argument and the exchange name is the second argument.
+ * The remaining QMF method properties are populated form config parsed from the command line.
+ */
+ private void addExchange(final String[] args)
+ {
+ if (args.length < 2)
+ {
+ usage();
+ }
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ if (_durable)
+ {
+ properties.put("durable", true);
+ }
+
+ properties.put("exchange-type", args[0]);
+
+ if (_msgSequence)
+ {
+ properties.put(MSG_SEQUENCE, 1l);
+ }
+
+ if (_ive)
+ {
+ properties.put(IVE, 1l);
+ }
+
+ if (_altExchange != null)
+ {
+ properties.put("alternate-exchange", _altExchange);
+ }
+
+ QmfData arguments = new QmfData();
+ arguments.setValue("type", "exchange");
+ arguments.setValue("name", args[1]);
+ arguments.setValue("properties", properties);
+
+ try
+ {
+ _broker.invokeMethod("create", arguments);
+ }
+ catch (QmfException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ // passive exchange creation not implemented yet (not sure how to do it using QMF2)
+ }
+
+ /**
+ * Add a queue using the QMF "create" method.
+ * @param args the queue name is the first argument.
+ * The remaining QMF method properties are populated form config parsed from the command line.
+ */
+ private void addQueue(final String[] args)
+ {
+ if (args.length < 1)
+ {
+ usage();
+ }
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ for (String a : extraArguments)
+ {
+ String[] r = a.split("=");
+ String value = r.length == 2 ? r[1] : null;
+ properties.put(r[0], value);
+ }
+
+ if (_durable)
+ {
+ properties.put("durable", true);
+ properties.put(FILECOUNT, _fileCount);
+ properties.put(FILESIZE, _fileSize);
+ }
+
+ if (_maxQueueSize > 0)
+ {
+ properties.put(MAX_QUEUE_SIZE, _maxQueueSize);
+ }
+
+ if (_maxQueueCount > 0)
+ {
+ properties.put(MAX_QUEUE_COUNT, _maxQueueCount);
+ }
+
+ if (_limitPolicy.equals("reject"))
+ {
+ properties.put(POLICY_TYPE, "reject");
+ }
+ else if (_limitPolicy.equals("flow-to-disk"))
+ {
+ properties.put(POLICY_TYPE, "flow_to_disk");
+ }
+ else if (_limitPolicy.equals("ring"))
+ {
+ properties.put(POLICY_TYPE, "ring");
+ }
+ else if (_limitPolicy.equals("ring-strict"))
+ {
+ properties.put(POLICY_TYPE, "ring_strict");
+ }
+
+ if (_clusterDurable)
+ {
+ properties.put(CLUSTER_DURABLE, 1l);
+ }
+
+ if (_order.equals("lvq"))
+ {
+ properties.put(LVQ, 1l);
+ }
+ else if (_order.equals("lvq-no-browse"))
+ {
+ properties.put(LVQNB, 1l);
+ }
+
+ if (_eventGeneration > 0)
+ {
+ properties.put(QUEUE_EVENT_GENERATION, _eventGeneration);
+ }
+
+ if (_altExchange != null)
+ {
+ properties.put("alternate-exchange", _altExchange);
+ }
+
+ if (_flowStopSize > 0)
+ {
+ properties.put(FLOW_STOP_SIZE, _flowStopSize);
+ }
+
+ if (_flowResumeSize > 0)
+ {
+ properties.put(FLOW_RESUME_SIZE, _flowResumeSize);
+ }
+
+ if (_flowStopCount > 0)
+ {
+ properties.put(FLOW_STOP_COUNT, _flowStopCount);
+ }
+
+ if (_flowResumeCount > 0)
+ {
+ properties.put(FLOW_RESUME_COUNT, _flowResumeCount);
+ }
+
+ QmfData arguments = new QmfData();
+ arguments.setValue("type", "queue");
+ arguments.setValue("name", args[0]);
+ arguments.setValue("properties", properties);
+
+ try
+ {
+ _broker.invokeMethod("create", arguments);
+ }
+ catch (QmfException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ // passive queue creation not implemented yet (not sure how to do it using QMF2)
+ }
+
+ /**
+ * Remove an exchange using the QMF "delete" method.
+ * @param args the exchange name is the first argument.
+ * The remaining QMF method properties are populated form config parsed from the command line.
+ */
+ private void delExchange(final String[] args)
+ {
+ if (args.length < 1)
+ {
+ usage();
+ }
+
+ QmfData arguments = new QmfData();
+ arguments.setValue("type", "exchange");
+ arguments.setValue("name", args[0]);
+
+ try
+ {
+ _broker.invokeMethod("delete", arguments);
+ }
+ catch (QmfException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ /**
+ * Remove a queue using the QMF "delete" method.
+ * @param args the queue name is the first argument.
+ * The remaining QMF method properties are populated form config parsed from the command line.
+ */
+ private void delQueue(final String[] args)
+ {
+ if (args.length < 1)
+ {
+ usage();
+ }
+
+ if (_ifEmpty || _ifUnused)
+ { // Check the selected queue object to see if it is not empty or is in use
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+ for (QmfConsoleData queue : queues)
+ {
+ ObjectId queueId = queue.getObjectId();
+ String name = queue.getStringValue("name");
+ if (name.equals(args[0]))
+ {
+ long msgDepth = queue.getLongValue("msgDepth");
+ if (_ifEmpty == true && msgDepth > 0)
+ {
+ System.out.println("Cannot delete queue " + name + "; queue not empty");
+ return;
+ }
+
+ long consumerCount = queue.getLongValue("consumerCount");
+ if (_ifUnused == true && consumerCount > 0)
+ {
+ System.out.println("Cannot delete queue " + name + "; queue in use");
+ return;
+ }
+ }
+ }
+ }
+
+ QmfData arguments = new QmfData();
+ arguments.setValue("type", "queue");
+ arguments.setValue("name", args[0]);
+
+ try
+ {
+ _broker.invokeMethod("delete", arguments);
+ }
+ catch (QmfException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ /**
+ * Add a binding using the QMF "create" method.
+ * @param args the exchange name is the first argument, the queue name is the second argument and the binding key
+ * is the third argument.
+ * The remaining QMF method properties are populated form config parsed from the command line.
+ */
+ private void bind(final String[] args)
+ {
+ if (args.length < 2)
+ {
+ usage();
+ }
+
+ // Look up exchange objects to find the type of the selected exchange
+ String exchangeType = null;
+ List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
+ for (QmfConsoleData exchange : exchanges)
+ {
+ String name = exchange.getStringValue("name");
+ if (args[0].equals(name))
+ {
+ exchangeType = exchange.getStringValue("type");
+ break;
+ }
+ }
+
+ if (exchangeType == null)
+ {
+ System.out.println("Exchange " + args[0] + " is invalid");
+ return;
+ }
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ if (exchangeType.equals("xml"))
+ {
+ if (_file == null)
+ {
+ System.out.println("Invalid args to bind xml: need an input file or stdin");
+ return;
+ }
+
+ String xquery = null;
+ if (_file.equals("-"))
+ { // Read xquery off stdin
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ try
+ {
+ StringBuilder buf = new StringBuilder();
+ String line;
+ while ((line = in.readLine()) != null) // read until eof
+ {
+ buf.append(line + "\n");
+ }
+ xquery = buf.toString();
+ }
+ catch (IOException ioe)
+ {
+ System.out.println("Exception " + ioe + " while reading stdin");
+ return;
+ }
+ }
+ else
+ { // Read xquery from input file
+ File file = new File(_file);
+ try
+ {
+ FileInputStream fin = new FileInputStream(file);
+ try
+ {
+ byte content[] = new byte[(int)file.length()];
+ fin.read(content);
+ xquery = new String(content);
+ }
+ finally
+ {
+ fin.close();
+ }
+ }
+ catch (FileNotFoundException e)
+ {
+ System.out.println("File " + _file + " not found");
+ return;
+ }
+ catch (IOException ioe)
+ {
+ System.out.println("Exception " + ioe + " while reading " + _file);
+ return;
+ }
+ }
+ properties.put("xquery", xquery);
+ }
+ else if (exchangeType.equals("headers"))
+ {
+ if (args.length < 5)
+ {
+ System.out.println("Invalid args to bind headers: need 'any'/'all' plus conditions");
+ return;
+ }
+ String op = args[3];
+ if (op.equals("all") || op.equals("any"))
+ {
+ properties.put("x-match", op);
+ String[] bindings = Arrays.copyOfRange(args, 4, args.length);
+ for (String binding : bindings)
+ {
+ if (binding.contains("="))
+ {
+ binding = binding.split(",")[0];
+ String[] kv = binding.split("=");
+ properties.put(kv[0], kv[1]);
+ }
+ }
+ }
+ else
+ {
+ System.out.println("Invalid condition arg to bind headers, need 'any' or 'all', not '" + op + "'");
+ return;
+ }
+ }
+
+ String bindingIdentifier = args[0] + "/" + args[1];
+ if (args.length > 2)
+ {
+ bindingIdentifier = bindingIdentifier + "/" + args[2];
+ }
+
+ QmfData arguments = new QmfData();
+ arguments.setValue("type", "binding");
+ arguments.setValue("name", bindingIdentifier);
+ arguments.setValue("properties", properties);
+
+ try
+ {
+ _broker.invokeMethod("create", arguments);
+ }
+ catch (QmfException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ /**
+ * Remove a binding using the QMF "delete" method.
+ * @param args the exchange name is the first argument, the queue name is the second argument and the binding key
+ * is the third argument.
+ * The remaining QMF method properties are populated form config parsed from the command line.
+ */
+ private void unbind(final String[] args)
+ {
+ if (args.length < 2)
+ {
+ usage();
+ }
+
+ String bindingIdentifier = args[0] + "/" + args[1];
+ if (args.length > 2)
+ {
+ bindingIdentifier = bindingIdentifier + "/" + args[2];
+ }
+
+ QmfData arguments = new QmfData();
+ arguments.setValue("type", "binding");
+ arguments.setValue("name", bindingIdentifier);
+
+ try
+ {
+ _broker.invokeMethod("delete", arguments);
+ }
+ catch (QmfException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ /**
+ * Create an instance of QpidConfig.
+ *
+ * @param args the command line arguments.
+ */
+ public QpidConfig(final String[] args)
+ {
+ String[] longOpts = {"help", "durable", "cluster-durable", "bindings", "broker-addr=", "file-count=",
+ "file-size=", "max-queue-size=", "max-queue-count=", "limit-policy=",
+ "order=", "sequence", "ive", "generate-queue-events=", "force", "force-if-not-empty",
+ "force-if-used", "alternate-exchange=", "passive", "timeout=", "file=", "flow-stop-size=",
+ "flow-resume-size=", "flow-stop-count=", "flow-resume-count=", "argument="};
+
+ try
+ {
+ GetOpt getopt = new GetOpt(args, "ha:bf:", longOpts);
+ List<String[]> optList = getopt.getOptList();
+ String[] cargs = {};
+ cargs = getopt.getEncArgs().toArray(cargs);
+
+ //System.out.println("optList");
+ for (String[] opt : optList)
+ {
+ //System.out.println(opt[0] + ":" + opt[1]);
+
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ options();
+ }
+
+ if (opt[0].equals("-b") || opt[0].equals("--bindings"))
+ {
+ _recursive = true;
+ }
+
+ if (opt[0].equals("-a") || opt[0].equals("--broker-addr"))
+ {
+ _host = opt[1];
+ }
+
+ if (opt[0].equals("-f") || opt[0].equals("--file"))
+ {
+ _file = opt[1];
+ }
+
+ if (opt[0].equals("--timeout"))
+ {
+ _connTimeout = Integer.parseInt(opt[1]);
+ }
+
+ if (opt[0].equals("--alternate-exchange"))
+ {
+ _altExchange = opt[1];
+ }
+
+ if (opt[0].equals("--passive"))
+ {
+ _passive = true;
+ }
+
+ if (opt[0].equals("--durable"))
+ {
+ _durable = true;
+ }
+
+ if (opt[0].equals("--cluster-durable"))
+ {
+ _clusterDurable = true;
+ }
+
+ if (opt[0].equals("--file-count"))
+ {
+ _fileCount = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--file-size"))
+ {
+ _fileSize = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--max-queue-size"))
+ {
+ _maxQueueSize = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--max-queue-count"))
+ {
+ _maxQueueCount = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--limit-policy"))
+ {
+ _limitPolicy = opt[1];
+ }
+
+ if (opt[0].equals("--flow-stop-size"))
+ {
+ _flowStopSize = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--flow-resume-size"))
+ {
+ _flowResumeSize = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--flow-stop-count"))
+ {
+ _flowStopCount = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--flow-resume-count"))
+ {
+ _flowResumeCount = Long.parseLong(opt[1]);
+ }
+
+ boolean validPolicy = false;
+ String[] validPolicies = {"none", "reject", "flow-to-disk", "ring", "ring-strict"};
+ for (String i : validPolicies)
+ {
+ if (_limitPolicy.equals(i))
+ {
+ validPolicy = true;
+ break;
+ }
+ }
+
+ if (!validPolicy)
+ {
+ System.err.println("Error: Invalid --limit-policy argument");
+ System.exit(1);
+ }
+
+ if (opt[0].equals("--order"))
+ {
+ _order = opt[1];
+ }
+
+ boolean validOrder = false;
+ String[] validOrders = {"fifo", "lvq", "lvq-no-browse"};
+ for (String i : validOrders)
+ {
+ if (_order.equals(i))
+ {
+ validOrder = true;
+ break;
+ }
+ }
+
+ if (!validOrder)
+ {
+ System.err.println("Error: Invalid --order argument");
+ System.exit(1);
+ }
+
+ if (opt[0].equals("--sequence"))
+ {
+ _msgSequence = true;
+ }
+
+ if (opt[0].equals("--ive"))
+ {
+ _ive = true;
+ }
+
+ if (opt[0].equals("--generate-queue-events"))
+ {
+ _eventGeneration = Long.parseLong(opt[1]);
+ }
+
+ if (opt[0].equals("--force"))
+ {
+ _ifEmpty = false;
+ _ifUnused = false;
+ }
+
+ if (opt[0].equals("--force-if-not-empty"))
+ {
+ _ifEmpty = false;
+ }
+
+ if (opt[0].equals("--force-if-used"))
+ {
+ _ifUnused = false;
+ }
+
+ if (opt[0].equals("--argument"))
+ {
+ extraArguments.add(opt[1]);
+ }
+ }
+
+ Connection connection = ConnectionHelper.createConnection(_host, "{reconnect: true}");
+ _console = new Console();
+ _console.disableEvents(); // Optimisation, as we're only doing getObjects() calls.
+ _console.addConnection(connection);
+ List<QmfConsoleData> brokers = _console.getObjects("org.apache.qpid.broker", "broker");
+ if (brokers.isEmpty())
+ {
+ System.out.println("No broker QmfConsoleData returned");
+ System.exit(1);
+ }
+
+ _broker = brokers.get(0);
+
+ int nargs = cargs.length;
+ if (nargs == 0)
+ {
+ overview();
+ }
+ else
+ {
+ String cmd = cargs[0];
+ String modifier = "";
+
+ if (nargs > 1)
+ {
+ modifier = cargs[1];
+ }
+
+ if (cmd.equals("exchanges"))
+ {
+ if (_recursive)
+ {
+ exchangeListRecurse(modifier);
+ }
+ else
+ {
+ exchangeList(modifier);
+ }
+ }
+ else if (cmd.equals("queues"))
+ {
+ if (_recursive)
+ {
+ queueListRecurse(modifier);
+ }
+ else
+ {
+ queueList(modifier);
+ }
+ }
+ else if (cmd.equals("add"))
+ {
+ if (modifier.equals("exchange"))
+ {
+ addExchange(Arrays.copyOfRange(cargs, 2, cargs.length));
+ }
+ else if (modifier.equals("queue"))
+ {
+ addQueue(Arrays.copyOfRange(cargs, 2, cargs.length));
+ }
+ else
+ {
+ usage();
+ }
+ }
+ else if (cmd.equals("del"))
+ {
+ if (modifier.equals("exchange"))
+ {
+ delExchange(Arrays.copyOfRange(cargs, 2, cargs.length));
+ }
+ else if (modifier.equals("queue"))
+ {
+ delQueue(Arrays.copyOfRange(cargs, 2, cargs.length));
+ }
+ else
+ {
+ usage();
+ }
+ }
+ else if (cmd.equals("bind"))
+ {
+ bind(Arrays.copyOfRange(cargs, 1, cargs.length));
+ }
+ else if (cmd.equals("unbind"))
+ {
+ unbind(Arrays.copyOfRange(cargs, 1, cargs.length));
+ }
+ else
+ {
+ usage();
+ }
+ }
+ }
+ catch (QmfException e)
+ {
+ System.err.println(e.toString());
+ usage();
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.err.println(e.toString());
+ usage();
+ }
+ }
+
+ /**
+ * Runs QpidConfig.
+ * @param args the command line arguments.
+ */
+ public static void main(String[] args)
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ // As of Qpid 0.16 the Session Dispatcher Thread is non-Daemon so the JVM gets prevented from exiting.
+ // Setting the following property to true makes it a Daemon Thread.
+ System.setProperty("qpid.jms.daemon.dispatcher", "true");
+
+ QpidConfig qpidConfig = new QpidConfig(args);
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidCtrl.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidCtrl.java
new file mode 100644
index 0000000000..d35786cce4
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidCtrl.java
@@ -0,0 +1,358 @@
+/*
+ *
+ * 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.qmf2.tools;
+
+// JMS Imports
+import javax.jms.Connection;
+
+// Misc Imports
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import org.apache.qpid.qmf2.util.GetOpt;
+
+// Reuse this class as it provides a handy mechanism to parse an args String into a Map
+import org.apache.qpid.messaging.util.AddressParser;
+
+/**
+ * A tool to allow QMF2 methods to be invoked from the command line.
+ * <pre>
+ * Usage: QpidCtrl [options] command [args]
+ * The args need to be in a Stringified Map format (similar to an Address String)
+ * e.g. to set broker log level: QpidCtrl setLogLevel "{level:\"debug+:Broker\"}"
+ * The listValues command lists property names and values of the specified object.
+ * The listObjects command lists all objects of the specified package and class.
+ *
+ * Options:
+ * -h, --help show this help message and exit
+ * -v enable logging
+ * -a &lt;address&gt;, --broker-address=&lt;address&gt;
+ * broker-addr is in the form: [username/password@]
+ * hostname | ip-address [:&lt;port&gt;] ex: localhost,
+ * 10.1.1.7:10000, broker-host:10000,
+ * guest/guest@localhost
+ * -c &lt;class&gt;, --class=&lt;class&gt;
+ * class of object on which command is being invoked
+ * (default broker)
+ * -p &lt;package&gt;, --package=&lt;package&gt;
+ * package of object on which command is being invoked
+ * (default org.apache.qpid.broker)
+ * -i &lt;id&gt;, --id=&lt;id&gt; identifier of object on which command is being invoked
+ * (default amqp-broker)
+ * --agent=&lt;agent name&gt;
+ * The name of the Agent to which commands will be sent
+ * This will try to match &lt;agent name&gt; against the Agent name
+ * the Agent product name and will also check if the Agent name
+ * contains the &lt;agent name&gt; String
+ * (default qpidd)
+ * --sasl-mechanism=&lt;mech&gt;
+ * SASL mechanism for authentication (e.g. EXTERNAL,
+ * ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL
+ * automatically picks the most secure available
+ * mechanism - use this option to override.
+ * </pre>
+ * Examples (Note the quotes and escaped quotes are significant!):
+ * <p>
+ * Get the current broker log level:
+ * <pre>QpidCtrl getLogLevel</pre>
+ *
+ * Set the current broker log level to notice+:
+ * <pre>QpidCtrl setLogLevel "{level:\"notice+\"}"</pre>
+ *
+ * Set the current broker log level to debug+ for all Management Objects:
+ * <pre>QpidCtrl setLogLevel "{level:\"debug+\"}"</pre>
+ *
+ * Set the current broker log level to debug+ for just the Broker Management Object:
+ * <pre>QpidCtrl setLogLevel "{level:\"debug+:Broker\"}"</pre>
+ *
+ * List the properties of the qmf.default.direct exchange:
+ * <pre>QpidCtrl -c exchange -i qmf.default.direct listValues</pre>
+ *
+ * Create a queue called test with a flow-to-disk limit policy:
+ * <pre>QpidCtrl create "{type:queue,name:test,properties:{'qpid.policy_type':ring}}"</pre>
+ *
+ * Delete a queue called test:
+ * <pre>QpidCtrl delete "{type:queue,name:test}"</pre>
+ *
+ * Create a binding called bind1 between the amq.match exchange and the test queue matching the headers name=fadams
+ * and gender=male:
+ * <pre>QpidCtrl create "{type:binding,name:'amq.match/test/bind1',properties:{x-match:all,name:fadams,gender:male}}"</pre>
+ *
+ * Delete the binding called bind1 between the amq.match exchange and the test queue:
+ * <pre>QpidCtrl delete "{type:binding,name:'amq.match/test/bind1'}"</pre>
+ *
+ * Get the broker to echo a message:
+ * <pre>QpidCtrl echo "{sequence:1234,body:'Peaches En Regalia'}"</pre>
+ *
+ * Invoke the event method on the gizmo Agent (launch gizmo Agent via AgentTest):
+ * <pre>QpidCtrl -p com.profitron.gizmo -c control -i OPERATIONAL --agent=gizmo event</pre>
+ *
+ * Invoke the create_child method on the gizmo Agent (launch gizmo Agent via AgentTest):
+ * <pre>QpidCtrl -p com.profitron.gizmo -c control -i OPERATIONAL --agent=gizmo create_child "{name:monkeyBoy}"</pre>
+ *
+ * Invoke the stop method on the gizmo Agent (launch gizmo Agent via AgentTest):
+ * <pre>QpidCtrl -p com.profitron.gizmo -c control -i OPERATIONAL --agent=gizmo stop "{message:'Will I dream?'}"</pre>
+ *
+ * @author Fraser Adams
+ */
+public final class QpidCtrl
+{
+ private static final String _usage =
+ "Usage: QpidCtrl [options] command [args]\n" +
+ "The args need to be in a Stringified Map format (similar to an Address String)\n" +
+ "e.g. to set broker log level: QpidCtrl setLogLevel \"{level:\\\"debug+:Broker\\\"}\"\n" +
+ "The listValues command lists property names and values of the specified object.\n" +
+ "The listObjects command lists all objects of the specified package and class.\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit\n" +
+ " -v enable logging\n" +
+ " -a <address>, --broker-address=<address>\n" +
+ " broker-addr is in the form: [username/password@]\n" +
+ " hostname | ip-address [:<port>] ex: localhost,\n" +
+ " 10.1.1.7:10000, broker-host:10000,\n" +
+ " guest/guest@localhost\n" +
+ " -c <class>, --class=<class>\n" +
+ " class of object on which command is being invoked\n" +
+ " (default broker)\n" +
+ " -p <package>, --package=<package>\n" +
+ " package of object on which command is being invoked\n" +
+ " (default org.apache.qpid.broker)\n" +
+ " -i <id>, --id=<id> identifier of object on which command is being invoked\n" +
+ " (default amqp-broker)\n" +
+ " --agent=<agent name>\n" +
+ " The name of the Agent to which commands will be sent\n" +
+ " This will try to match <agent name> against the Agent name,\n" +
+ " the Agent product name and will also check if the Agent name\n" +
+ " contains the <agent name> String\n" +
+ " (default qpidd)\n" +
+ " --sasl-mechanism=<mech>\n" +
+ " SASL mechanism for authentication (e.g. EXTERNAL,\n" +
+ " ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL\n" +
+ " automatically picks the most secure available\n" +
+ " mechanism - use this option to override.\n";
+
+ private Console _console;
+
+ /**
+ * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection.
+ * @param url the Connection URL.
+ * @param connectionOptions the connection options String to pass to ConnectionHelper.
+ * @param pkg the package name of the object we're invoking the method on.
+ * @param cls the class name of the object we're invoking the method on.
+ * @param id the ObjectId name of the object we're invoking the method on.
+ * @param agentName the name of the Agent to invoke the QMF method on.
+ * @param command the QMF method we're invoking.
+ * @param args the Stringified Map form of the method arguments.
+ */
+ public QpidCtrl(final String url, final String connectionOptions, final String pkg, final String cls,
+ final String id, final String agentName, final String command, final String args)
+ {
+ try
+ {
+ Connection connection = ConnectionHelper.createConnection(url, connectionOptions);
+ _console = new Console();
+ _console.addConnection(connection);
+
+ // Find the specified Agent
+ Agent agent = _console.findAgent(agentName);
+ if (agent == null)
+ {
+ System.out.println("Agent " + agentName + " not found");
+ System.exit(1);
+ }
+
+ List<Agent> agentList = Arrays.asList(new Agent[] {agent});
+ List<QmfConsoleData> objects = _console.getObjects(pkg, cls, agentList);
+
+ // Parse the args String
+ QmfData inArgs = (args == null) ? new QmfData() : new QmfData(new AddressParser(args).map());
+
+ // Find the required QmfConsoleData object and invoke the specified command
+ MethodResult results = null;
+ for (QmfConsoleData object : objects)
+ {
+ String objectName = object.getObjectId().getObjectName();
+ if (command.equals("listObjects"))
+ {
+ System.out.println(objectName);
+ }
+ else
+ {
+ if (objectName.contains(id))
+ { // Use contains as ObjectNames may comprise other identifiers tha make using equals impractical
+ if (command.equals("listValues"))
+ {
+ object.listValues();
+ System.exit(1);
+ }
+ else
+ {
+ results = object.invokeMethod(command, inArgs);
+ }
+ break;
+ }
+ }
+ }
+
+ if (results == null)
+ {
+ if (objects.size() == 0)
+ {
+ System.out.println("getObjects(" + pkg + ", " + cls + ", " + agentName + ") returned no objects.");
+ }
+ else
+ {
+ System.out.println("Id " + id + " not found in " + pkg + ":" + cls);
+ }
+ }
+ else
+ {
+ if (results.succeeded())
+ {
+ results.listValues();
+ }
+ else
+ {
+ System.err.println ("QmfException " + results.getQmfException().getMessage() +
+ " returned from " + command + " method");
+ }
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidCtrl constructor");
+ }
+ }
+
+ /**
+ * Runs QpidCtrl.
+ * @param args the command line arguments.
+ */
+ public static void main(final String[] args)
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ // As of Qpid 0.16 the Session Dispatcher Thread is non-Daemon so the JVM gets prevented from exiting.
+ // Setting the following property to true makes it a Daemon Thread.
+ System.setProperty("qpid.jms.daemon.dispatcher", "true");
+
+ String[] longOpts = {"help", "broker-address=", "class=", "package=", "id=", "agent=", "sasl-mechanism="};
+ try
+ {
+ String host = "localhost";
+ String connectionOptions = "{reconnect: true}";
+ String cls = "broker";
+ String pkg = "org.apache.qpid.broker";
+ String id = "amqp-broker";
+ String agentName = "qpidd";
+ String command = null;
+ String arg = null;
+
+ GetOpt getopt = new GetOpt(args, "ha:c:p:i:v", longOpts);
+ List<String[]> optList = getopt.getOptList();
+ String[] cargs = {};
+ cargs = getopt.getEncArgs().toArray(cargs);
+
+ for (String[] opt : optList)
+ {
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ System.out.println(_usage);
+ System.out.println(_options);
+ System.exit(1);
+ }
+ else if (opt[0].equals("-a") || opt[0].equals("--broker-address"))
+ {
+ host = opt[1];
+ }
+ else if (opt[0].equals("-c") || opt[0].equals("--class"))
+ {
+ cls = opt[1];
+ }
+ else if (opt[0].equals("-p") || opt[0].equals("--package"))
+ {
+ pkg = opt[1];
+ }
+ else if (opt[0].equals("-i") || opt[0].equals("--id"))
+ {
+ id = opt[1];
+ }
+ else if (opt[0].equals("--agent"))
+ {
+ agentName = opt[1];
+ }
+ else if (opt[0].equals("-v"))
+ {
+ System.setProperty("amqj.logging.level", "DEBUG");
+ }
+ else if (opt[0].equals("--sasl-mechanism"))
+ {
+ connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
+ }
+ }
+
+ if (cargs.length < 1 || cargs.length > 2)
+ {
+ System.out.println(Arrays.asList(cargs));
+ System.out.println(_usage);
+ System.exit(1);
+ }
+
+ command = cargs[0];
+
+ if (cargs.length == 2)
+ {
+ arg = cargs[1];
+ if (!arg.startsWith("{") || !arg.endsWith("}"))
+ {
+ System.out.println("Incorrect format for args.");
+ System.out.println("This needs to be in a Stringified Map format similar to an Address String");
+ System.exit(1);
+ }
+ }
+
+ QpidCtrl qpidCtrl = new QpidCtrl(host, connectionOptions, pkg, cls, id, agentName, command, arg);
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(_usage);
+ System.out.println(e.getMessage());
+ System.exit(1);
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidPrintEvents.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidPrintEvents.java
new file mode 100644
index 0000000000..d5912344c7
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidPrintEvents.java
@@ -0,0 +1,210 @@
+/*
+ *
+ * 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.qmf2.tools;
+
+// JMS Imports
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import org.apache.qpid.qmf2.util.GetOpt;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * Collect and print events from one or more Qpid message brokers.
+ * <pre>
+ * If no broker-addr is supplied, QpidPrintEvents connects to 'localhost:5672'.
+ *
+ * [broker-addr] syntax:
+ *
+ * [username/password@] hostname
+ * ip-address [:&lt;port&gt;]
+ *
+ * Examples:
+ *
+ * $ QpidPrintEvents localhost:5672
+ * $ QpidPrintEvents 10.1.1.7:10000
+ * $ QpidPrintEvents guest/guest@broker-host:10000
+ *
+ * Options:
+ * -h, --help show this help message and exit
+ * --heartbeats Use heartbeats.
+ * --sasl-mechanism=&lt;mech&gt;
+ * SASL mechanism for authentication (e.g. EXTERNAL,
+ * ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL
+ * automatically picks the most secure available
+ * mechanism - use this option to override.
+ * </pre>
+ * @author Fraser Adams
+ */
+public final class QpidPrintEvents implements QmfEventListener
+{
+ private static final String _usage =
+ "Usage: QpidPrintEvents [options] [broker-addr]...\n";
+
+ private static final String _description =
+ "Collect and print events from one or more Qpid message brokers.\n" +
+ "\n" +
+ "If no broker-addr is supplied, QpidPrintEvents connects to 'localhost:5672'.\n" +
+ "\n" +
+ "[broker-addr] syntax:\n" +
+ "\n" +
+ "[username/password@] hostname\n" +
+ "ip-address [:<port>]\n" +
+ "\n" +
+ "Examples:\n" +
+ "\n" +
+ "$ QpidPrintEvents localhost:5672\n" +
+ "$ QpidPrintEvents 10.1.1.7:10000\n" +
+ "$ QpidPrintEvents guest/guest@broker-host:10000\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit\n" +
+ " --heartbeats Use heartbeats.\n" +
+ " --sasl-mechanism=<mech>\n" +
+ " SASL mechanism for authentication (e.g. EXTERNAL,\n" +
+ " ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL\n" +
+ " automatically picks the most secure available\n" +
+ " mechanism - use this option to override.\n";
+
+ private final String _url;
+ private Console _console;
+
+ /**
+ * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection.
+ * @param url the connection URL.
+ * @param connectionOptions the options String to pass to ConnectionHelper.
+ */
+ public QpidPrintEvents(final String url, final String connectionOptions)
+ {
+ System.out.println("Connecting to " + url);
+ _url = url;
+ try
+ {
+ Connection connection = ConnectionHelper.createConnection(url, connectionOptions);
+ _console = new Console(this);
+ _console.addConnection(connection);
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidPrintEvents constructor");
+ }
+ }
+
+ /**
+ * Checks if the WorkItem is an EventReceivedWorkItem and if it is extracts and renders the QmfEvent.
+ * @param wi a QMF2 WorkItem object
+ */
+ public void onEvent(final WorkItem wi)
+ {
+ if (wi instanceof EventReceivedWorkItem)
+ {
+ EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+ QmfEvent event = item.getEvent();
+ System.out.println(event + " broker=" + _url);
+ }
+ }
+
+ /**
+ * Runs QpidPrintEvents.
+ * @param args the command line arguments.
+ */
+ public static void main(final String[] args)
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ String[] longOpts = {"help", "heartbeats", "sasl-mechanism="};
+ try
+ {
+ String connectionOptions = "{reconnect: true}";
+ GetOpt getopt = new GetOpt(args, "h", longOpts);
+ List<String[]> optList = getopt.getOptList();
+ String[] cargs = {};
+ cargs = getopt.getEncArgs().toArray(cargs);
+ for (String[] opt : optList)
+ {
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ System.out.println(_usage);
+ System.out.println(_description);
+ System.out.println(_options);
+ System.exit(1);
+ }
+ else if (opt[0].equals("--heartbeats"))
+ {
+ // Ignore Java uses heartbeats by default
+ }
+ else if (opt[0].equals("--sasl-mechanism"))
+ {
+ connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
+ }
+ }
+
+ int nargs = cargs.length;
+ if (nargs == 0)
+ {
+ cargs = new String[] {"localhost"};
+ }
+
+ for (String url : cargs)
+ {
+ QpidPrintEvents eventPrinter = new QpidPrintEvents(url, connectionOptions);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(_usage);
+ System.exit(1);
+ }
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("QpidPrintEvents main(): IOException: " + e.getMessage());
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidQueueStats.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidQueueStats.java
new file mode 100644
index 0000000000..7558da0e28
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QpidQueueStats.java
@@ -0,0 +1,374 @@
+/*
+ *
+ * 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.qmf2.tools;
+
+// JMS Imports
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.AgentRestartedWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+
+import org.apache.qpid.qmf2.console.SubscribeIndication;
+import org.apache.qpid.qmf2.console.SubscribeParams;
+import org.apache.qpid.qmf2.console.SubscriptionIndicationWorkItem;
+
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import org.apache.qpid.qmf2.util.GetOpt;
+
+/**
+ * Collect and print queue statistics.
+ * <pre>
+ * Usage: QpidQueueStats [options]
+ *
+ * Options:
+ * -h, --help show this help message and exit
+ * -a &lt;address&gt;, --broker-address=&lt;address&gt;
+ * broker-addr is in the form: [username/password@]
+ * hostname | ip-address [:&lt;port&gt;] ex: localhost,
+ * 10.1.1.7:10000, broker-host:10000,
+ * guest/guest@localhost
+ * -f &lt;filter&gt;, --filter=&lt;filter&gt;
+ * a list of comma separated queue names (regex are
+ * accepted) to show
+ * --sasl-mechanism=&lt;mech&gt;
+ * SASL mechanism for authentication (e.g. EXTERNAL,
+ * ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL
+ * automatically picks the most secure available
+ * mechanism - use this option to override.
+ * </pre>
+ * @author Fraser Adams
+ */
+public final class QpidQueueStats implements QmfEventListener
+{
+ private final class Stats
+ {
+ private final String _name;
+ private QmfConsoleData _data;
+
+ public Stats(final String name, final QmfConsoleData data)
+ {
+ _name = name;
+ _data = data;
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ public QmfConsoleData getData()
+ {
+ return _data;
+ }
+
+ public void setData(final QmfConsoleData data)
+ {
+ _data = data;
+ }
+ }
+
+ private static final String _usage =
+ "Usage: QpidQueueStats [options]\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit\n" +
+ " -a <address>, --broker-address=<address>\n" +
+ " broker-addr is in the form: [username/password@]\n" +
+ " hostname | ip-address [:<port>] ex: localhost,\n" +
+ " 10.1.1.7:10000, broker-host:10000,\n" +
+ " guest/guest@localhost\n" +
+ " -f <filter>, --filter=<filter>\n" +
+ " a list of comma separated queue names (regex are\n" +
+ " accepted) to show\n" +
+ " --sasl-mechanism=<mech>\n" +
+ " SASL mechanism for authentication (e.g. EXTERNAL,\n" +
+ " ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL\n" +
+ " automatically picks the most secure available\n" +
+ " mechanism - use this option to override.\n";
+
+ private final String _url;
+ private final List<Pattern> _filter;
+ private Agent _broker;
+ private Console _console;
+ private Map<ObjectId, Stats> _objects = new HashMap<ObjectId, Stats>();
+ private String _subscriptionId = null;
+ private long _subscriptionDuration;
+ private long _startTime;
+
+ /**
+ * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection.
+ * @param url the connection URL.
+ * @param connectionOptions the options String to pass to ConnectionHelper.
+ * @param filter a list of regex Patterns used to choose the queues we wish to display.
+ */
+ public QpidQueueStats(final String url, final String connectionOptions, final List<Pattern> filter)
+ {
+ System.out.println("Connecting to " + url);
+ if (filter.size() > 0)
+ {
+ System.out.println("Filter = " + filter);
+ }
+ _url = url;
+ _filter = filter;
+ try
+ {
+ Connection connection = ConnectionHelper.createConnection(url, connectionOptions);
+ _console = new Console(this);
+ _console.addConnection(connection);
+
+ // Wait until the broker Agent has been discovered
+ _broker = _console.findAgent("broker");
+ if (_broker != null)
+ {
+ createQueueSubscription();
+ }
+
+ System.out.println("Hit Return to exit");
+ System.out.println(
+ "Queue Name Sec Depth Enq Rate Deq Rate");
+ System.out.println(
+ "=============================================================================================");
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidQueueStats constructor");
+ }
+ }
+
+ /**
+ * Create a Subscription to query for all queue objects
+ */
+ private void createQueueSubscription()
+ {
+ try
+ { // This QmfQuery simply does an ID query for objects with the className "queue"
+ QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("queue"));
+ SubscribeParams params = _console.createSubscription(_broker, query, "queueStatsHandle");
+ _subscriptionId = params.getSubscriptionId();
+ _subscriptionDuration = params.getLifetime() - 10; // Subtract 10 as we want to refresh before it times out
+ _startTime = System.currentTimeMillis();
+ }
+ catch (QmfException qmfe)
+ {
+ }
+ }
+
+ /**
+ * Main Event handler. Checks if the WorkItem is a SubscriptionIndicationWorkItem, if it is it stores the object
+ * in a Map and uses this to maintain state so we can record deltas such as enqueue and dequeue rates.
+ * <p>
+ * The AgentHeartbeatWorkItem is used to periodically compare the elapsed time against the Subscription duration
+ * so that we can refresh the Subscription (or create a new one if necessary) in order to continue receiving
+ * queue Management Object data from the broker.
+ * <p>
+ * When the AgentRestartedWorkItem is received we clear the state to remove any stale queue Management Objects.
+ * @param wi a QMF2 WorkItem object
+ */
+ public void onEvent(final WorkItem wi)
+ {
+ if (wi instanceof AgentHeartbeatWorkItem && _subscriptionId != null)
+ {
+ long elapsed = (long)Math.round((System.currentTimeMillis() - _startTime)/1000.0f);
+ if (elapsed > _subscriptionDuration)
+ {
+ try
+ {
+ _console.refreshSubscription(_subscriptionId);
+ _startTime = System.currentTimeMillis();
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidQueueStats onEvent");
+ createQueueSubscription();
+ }
+ }
+ }
+ else if (wi instanceof AgentRestartedWorkItem)
+ {
+ _objects.clear();
+ }
+ else if (wi instanceof SubscriptionIndicationWorkItem)
+ {
+ SubscriptionIndicationWorkItem item = (SubscriptionIndicationWorkItem)wi;
+ SubscribeIndication indication = item.getSubscribeIndication();
+ String correlationId = indication.getConsoleHandle();
+ if (correlationId.equals("queueStatsHandle"))
+ { // If it is (and it should be!!) then it's our queue object Subscription
+ List<QmfConsoleData> data = indication.getData();
+ for (QmfConsoleData record : data)
+ {
+ ObjectId id = record.getObjectId();
+ if (record.isDeleted())
+ { // If the object was deleted by the Agent we remove it from out Map
+ _objects.remove(id);
+ }
+ else
+ {
+ if (_objects.containsKey(id))
+ { // If the object is already in the Map it's likely to be a statistics push from the broker.
+ Stats stats = _objects.get(id);
+ String name = stats.getName();
+
+ boolean matches = false;
+ for (Pattern x : _filter)
+ { // Check the queue name against the regexes in the filter List (if any)
+ Matcher m = x.matcher(name);
+ if (m.find())
+ {
+ matches = true;
+ break;
+ }
+ }
+
+ if (_filter.isEmpty() || matches)
+ { // If there's no filter enabled or the filter matches the queue name we display statistics.
+ QmfConsoleData lastSample = stats.getData();
+ stats.setData(record);
+
+ float deltaTime = record.getUpdateTime() - lastSample.getUpdateTime();
+ if (deltaTime > 1000000000.0f)
+ {
+ float deltaEnqueues = record.getLongValue("msgTotalEnqueues") -
+ lastSample.getLongValue("msgTotalEnqueues");
+ float deltaDequeues = record.getLongValue("msgTotalDequeues") -
+ lastSample.getLongValue("msgTotalDequeues");
+ long msgDepth = record.getLongValue("msgDepth");
+ float enqueueRate = deltaEnqueues/(deltaTime/1000000000.0f);
+ float dequeueRate = deltaDequeues/(deltaTime/1000000000.0f);
+
+ System.out.printf("%-46s%10.2f%11d%13.2f%13.2f\n",
+ name, deltaTime/1000000000, msgDepth, enqueueRate, dequeueRate);
+ }
+ }
+ }
+ else
+ { // If the object isn't in the Map it's likely to be a properties push from the broker.
+ if (!record.hasValue("name"))
+ { // This probably won't happen, but if it does we refresh the object to get its full state.
+ try
+ {
+ record.refresh();
+ }
+ catch (QmfException qmfe)
+ {
+ }
+ }
+ String queueName = record.getStringValue("name");
+ _objects.put(id, new Stats(queueName, record));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Runs QpidQueueStats.
+ * @param args the command line arguments.
+ */
+ public static void main(final String[] args)
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ String[] longOpts = {"help", "broker-address=", "filter=", "sasl-mechanism="};
+ try
+ {
+ String host = "localhost";
+ String connectionOptions = "{reconnect: true}";
+ List<Pattern> filter = new ArrayList<Pattern>();
+ GetOpt getopt = new GetOpt(args, "ha:f:", longOpts);
+ List<String[]> optList = getopt.getOptList();
+
+ for (String[] opt : optList)
+ {
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ System.out.println(_usage);
+ System.out.println(_options);
+ System.exit(1);
+ }
+ else if (opt[0].equals("-a") || opt[0].equals("--broker-address"))
+ {
+ host = opt[1];
+ }
+ else if (opt[0].equals("-f") || opt[0].equals("--filter"))
+ {
+ String[] split = opt[1].split(",");
+ for (String s : split)
+ {
+ Pattern p = Pattern.compile(s);
+ filter.add(p);
+ }
+ }
+ else if (opt[0].equals("--sasl-mechanism"))
+ {
+ connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
+ }
+ }
+
+ QpidQueueStats queueStats = new QpidQueueStats(host, connectionOptions, filter);
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(_usage);
+ System.out.println(e.getMessage());
+ System.exit(1);
+ }
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("QpidQueueStats main(): IOException: " + e.getMessage());
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QueueFuse.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QueueFuse.java
new file mode 100644
index 0000000000..324b9bd1b5
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/tools/QueueFuse.java
@@ -0,0 +1,364 @@
+/*
+ *
+ * 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.qmf2.tools;
+
+// JMS Imports
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import org.apache.qpid.qmf2.util.GetOpt;
+
+/**
+ * QueueFuse provides protection to message producers from consumers who can't consume messages fast enough.
+ * <p>
+ * With the default "reject" limit policy when a queue exceeds its capacity an exception is thrown to the
+ * producer. This behaviour is unfortunate, because if there happen to be multiple consumers consuming
+ * messages from a given producer it is possible for a single slow consumer to cause message flow to be
+ * stopped to <u>all</u> consumers, in other words a de-facto denial of service may take place.
+ * <p>
+ * In an Enterprise environment it is likely that this sort of behaviour is unwelcome, so QueueFuse makes it
+ * possible for queueThresholdExceeded Events to be detected and for the offending queues to have messages
+ * purged, thus protecting the other consumers by preventing an exception being thrown to the message producer.
+ * <p>
+ * The original intention with this class was to unbind bindings to queues that exceed the threshold. This method
+ * works, but it has a number of disadvantages. In particular there is no way to unbind from (and thus protect)
+ * queues bound to the default direct exchange, in addition in order to unbind it is necessary to retrieve
+ * binding and exchange information, both of which require further exchanges with the broker (which is not
+ * desirable as when the queueThresholdExceeded occurs we need to act pretty quickly). Finally as it happens
+ * it is also necessary to purge some messages after unbinding anyway as if this is not done the queue remains
+ * in the flowStopped state and producers will eventually time out and throw an exception if this is not cleared.
+ * So all in all simply purging each time we cross the threshold is simpler and has the additional advantage that
+ * if and when the consumer speeds up message delivery will eventually return to normal.
+ *
+ * <pre>
+ * Usage: QueueFuse [options] [broker-addr]...
+ *
+ * Monitors one or more Qpid message brokers for queueThresholdExceeded Events.
+ *
+ * If a queueThresholdExceeded Event occurs messages are purged from the queue,
+ * in other words this class behaves rather like a fuse 'blowing' if the
+ * threshold gets exceeded.
+ *
+ * If no broker-addr is supplied, QueueFuse connects to 'localhost:5672'.
+ *
+ * [broker-addr] syntax:
+ *
+ * [username/password@] hostname
+ * ip-address [:&lt;port&gt;]
+ *
+ * Examples:
+ *
+ * $ QueueFuse localhost:5672
+ * $ QueueFuse 10.1.1.7:10000
+ * $ QueueFuse guest/guest@broker-host:10000
+ *
+ * Options:
+ * -h, --help show this help message and exit
+ * -f &lt;filter&gt;, --filter=&lt;filter&gt;
+ * a list of comma separated queue names (regex are
+ * accepted) to protect (default is to protect all).
+ * -p &lt;PERCENT&gt;, --purge=&lt;PERCENT&gt;\n" +
+ * The percentage of messages to purge when the queue\n" +
+ * threshold gets exceeded (default = 20%).\n" +
+ * N.B. if this gets set too low the fuse may not blow.\n" +
+ * --sasl-mechanism=&lt;mech&gt;
+ * SASL mechanism for authentication (e.g. EXTERNAL,
+ * ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL
+ * automatically picks the most secure available
+ * mechanism - use this option to override.
+ * </pre>
+ * @author Fraser Adams
+ */
+public final class QueueFuse implements QmfEventListener
+{
+ private static final String _usage =
+ "Usage: QueueFuse [options] [broker-addr]...\n";
+
+ private static final String _description =
+ "Monitors one or more Qpid message brokers for queueThresholdExceeded Events.\n" +
+ "\n" +
+ "If a queueThresholdExceeded Event occurs messages are purged from the queue,\n" +
+ "in other words this class behaves rather like a fuse 'blowing' if the\n" +
+ "threshold gets exceeded.\n" +
+ "\n" +
+ "If no broker-addr is supplied, QueueFuse connects to 'localhost:5672'.\n" +
+ "\n" +
+ "[broker-addr] syntax:\n" +
+ "\n" +
+ "[username/password@] hostname\n" +
+ "ip-address [:<port>]\n" +
+ "\n" +
+ "Examples:\n" +
+ "\n" +
+ "$ QueueFuse localhost:5672\n" +
+ "$ QueueFuse 10.1.1.7:10000\n" +
+ "$ QueueFuse guest/guest@broker-host:10000\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit\n" +
+ " -f <filter>, --filter=<filter>\n" +
+ " a list of comma separated queue names (regex are\n" +
+ " accepted) to protect (default is to protect all).\n" +
+ " -p <PERCENT>, --purge=<PERCENT>\n" +
+ " The percentage of messages to purge when the queue\n" +
+ " threshold gets exceeded (default = 20%).\n" +
+ " N.B. if this gets set too low the fuse may not blow.\n" +
+ " --sasl-mechanism=<mech>\n" +
+ " SASL mechanism for authentication (e.g. EXTERNAL,\n" +
+ " ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). SASL\n" +
+ " automatically picks the most secure available\n" +
+ " mechanism - use this option to override.\n";
+
+ private final String _url;
+ private final List<Pattern> _filter;
+ private final float _purge;
+ private Map<String, QmfConsoleData> _queueCache = new HashMap<String, QmfConsoleData>(50);
+ private Console _console;
+
+ /**
+ * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection.
+ * @param url the connection URL.
+ * @param connectionOptions the options String to pass to ConnectionHelper.
+ * @param filter a list of regex Patterns used to choose the queues we wish to protect.
+ * @param purge the ratio of messages that we wish to purge if the threshold gets exceeded.
+ */
+ public QueueFuse(final String url, final String connectionOptions, final List<Pattern> filter, final float purge)
+ {
+ System.out.println("QueueFuse Connecting to " + url);
+ if (filter.size() > 0)
+ {
+ System.out.println("Filter = " + filter);
+ }
+ _url = url;
+ _filter = filter;
+ _purge = purge;
+ try
+ {
+ Connection connection = ConnectionHelper.createConnection(url, connectionOptions);
+ _console = new Console(this);
+ _console.addConnection(connection);
+ updateQueueCache();
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught in QueueFuse constructor");
+ }
+ }
+
+ /**
+ * Looks up queue objects and stores them in _queueCache keyed by the queue name
+ */
+ private void updateQueueCache()
+ {
+ _queueCache.clear();
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+ for (QmfConsoleData queue : queues)
+ {
+ String queueName = queue.getStringValue("name");
+ _queueCache.put(queueName, queue);
+ }
+ }
+
+ /**
+ * Look up a queue object with the given name and if it's not a ring queue invoke the queue's purge method.
+ * @param queueName the name of the queue to purge
+ * @param msgDepth the number of messages on the queue, used to determine how many messages to purge.
+ */
+ private void purgeQueue(final String queueName, long msgDepth)
+ {
+ QmfConsoleData queue = _queueCache.get(queueName);
+
+ if (queue == null)
+ {
+ System.out.printf("%s ERROR QueueFuse.disconnectQueue() %s reference couldn't be found\n",
+ new Date().toString(), queueName);
+ }
+ else
+ { // If we've found a queue called queueName we then find the bindings that reference it.
+
+ Map args = (Map)queue.getValue("arguments");
+ String policyType = (String)args.get("qpid.policy_type");
+ if (policyType != null && policyType.equals("ring"))
+ { // If qpid.policy_type=ring we return.
+ return;
+ }
+
+ try
+ {
+ QmfData arguments = new QmfData();
+ arguments.setValue("request", (long)(_purge*msgDepth));
+ queue.invokeMethod("purge", arguments);
+ }
+ catch (QmfException e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Main Event handler.
+ * @param wi a QMF2 WorkItem object
+ */
+ public void onEvent(final WorkItem wi)
+ {
+ if (wi instanceof EventReceivedWorkItem)
+ {
+ EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+ Agent agent = item.getAgent();
+ QmfEvent event = item.getEvent();
+ String className = event.getSchemaClassId().getClassName();
+
+ if (className.equals("queueDeclare"))
+ {
+ updateQueueCache();
+ }
+ else if (className.equals("queueThresholdExceeded"))
+ {
+ String queueName = event.getStringValue("qName");
+ boolean matches = false;
+ for (Pattern x : _filter)
+ { // Check the queue name against the regexes in the filter List (if any)
+ Matcher m = x.matcher(queueName);
+ if (m.find())
+ {
+ matches = true;
+ break;
+ }
+ }
+
+ if (_filter.isEmpty() || matches)
+ { // If there's no filter enabled or the filter matches the queue name we call purgeQueue().
+ long msgDepth = event.getLongValue("msgDepth");
+ purgeQueue(queueName, msgDepth);
+ }
+ }
+ }
+ }
+
+ /**
+ * Runs QueueFuse.
+ * @param args the command line arguments.
+ */
+ public static void main(final String[] args)
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ String[] longOpts = {"help", "filter=", "purge=", "sasl-mechanism="};
+ try
+ {
+ boolean includeRingQueues = false;
+ String connectionOptions = "{reconnect: true}";
+ List<Pattern> filter = new ArrayList<Pattern>();
+ float purge = 0.2f;
+ GetOpt getopt = new GetOpt(args, "hf:p:", longOpts);
+ List<String[]> optList = getopt.getOptList();
+ String[] cargs = {};
+ cargs = getopt.getEncArgs().toArray(cargs);
+ for (String[] opt : optList)
+ {
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ System.out.println(_usage);
+ System.out.println(_description);
+ System.out.println(_options);
+ System.exit(1);
+ }
+ else if (opt[0].equals("-f") || opt[0].equals("--filter"))
+ {
+ String[] split = opt[1].split(",");
+ for (String s : split)
+ {
+ Pattern p = Pattern.compile(s);
+ filter.add(p);
+ }
+ }
+ else if (opt[0].equals("-p") || opt[0].equals("--purge"))
+ {
+ int percent = Integer.parseInt(opt[1]);
+ if (percent < 0 || percent > 100)
+ {
+ System.out.println(_usage);
+ System.exit(1);
+ }
+ purge = percent/100.0f;
+ }
+ else if (opt[0].equals("--sasl-mechanism"))
+ {
+ connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}";
+ }
+ }
+
+ int nargs = cargs.length;
+ if (nargs == 0)
+ {
+ cargs = new String[] {"localhost"};
+ }
+
+ for (String url : cargs)
+ {
+ QueueFuse queueFuse = new QueueFuse(url, connectionOptions, filter, purge);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(_usage);
+ System.out.println(e.getMessage());
+ System.exit(1);
+ }
+
+ try
+ { // Block here
+ Thread.currentThread().join();
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/ConnectionHelper.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/ConnectionHelper.java
new file mode 100644
index 0000000000..c0df65ef1c
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/ConnectionHelper.java
@@ -0,0 +1,862 @@
+/*
+ *
+ * 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.qmf2.util;
+
+// JMS Imports
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+
+// JNDI Imports
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Misc Imports
+import java.util.Map;
+import java.util.Properties;
+
+// Reuse this class as it provides a handy mechanism to parse an options String into a Map
+import org.apache.qpid.messaging.util.AddressParser;
+
+/**
+ * The Qpid M4 Java and C++ clients and the Python QMF tools all use different URL formats.
+ * This class provides helper methods to support a variety of URL formats and connection options
+ * in order to provide flexibility when creating connections.
+ * <p>
+ * Much of the following information is taken from <a href="https://cwiki.apache.org/qpid/url-format-proposal.html">
+ * New URL format for AMQP + Qpid</a>
+ * <p>
+ * <h3>AMQP 0-10 format</h3>
+ * C++ uses the AMQP 0-10 format: section 9.1.2 as follows:
+ * <pre>
+ * amqp_url = "amqp:" prot_addr_list
+ * prot_addr_list = [prot_addr ","]* prot_addr
+ * prot_addr = tcp_prot_addr | tls_prot_addr
+ *
+ * tcp_prot_addr = tcp_id tcp_addr
+ * tcp_id = "tcp:" | ""
+ * tcp_addr = [host [":" port] ]
+ * host = &lt;as per <a href="http://www.ietf.org/rfc/rfc3986.txt">rfc3986</a>&gt;
+ * port = number
+ * </pre>
+ * The AMQP 0-10 format only provides protocol address information for a (list of) brokers.
+ * <p>
+ * <p>
+ *
+ * <h3>Python tool BrokerURL format</h3>
+ * The Python tools bundled with Qpid such as qpid-config use a "BrokerURL" format with the following Address syntax:
+ * <pre>
+ * [&lt;user&gt;/&lt;pass&gt;@]&lt;hostname&gt; | &lt;ip-address&gt;[:&lt;port&gt;]
+ * </pre>
+ *
+ * <h3>Qpid M4 Java Connection URL format</h3>
+ * The Qpid M4 Java format provides additional options for connection options (user, password, vhost etc.)
+ * Documentation for this format may be found here: <a href="https://cwiki.apache.org/qpid/connection-url-format.html">
+ * Qpid M4 Java Connection URL Format</a>
+ * <p>
+ * Java ConnectionURLs look like this:
+ * <pre>
+ * amqp://[&lt;user&gt;:&lt;pass&gt;@][&lt;clientid&gt;]/&lt;virtualhost&gt;[?&lt;option&gt;='&lt;value&gt;'[&&lt;option&gt;='&lt;value&gt;']]
+ * </pre>
+ * This syntax is very powerful, but it can also be fairly complex to work with, especially when one realises
+ * that one of the options in the above syntax is brokerlist='&lt;broker url&gt;' where broker url is itself a URL
+ * of the format:
+ * <pre>
+ * &lt;transport&gt;://&lt;host&gt;[:&lt;port&gt;][?&lt;option&gt;='&lt;value&gt;'[&&lt;option&gt;='&lt;value&gt;']]
+ * </pre>
+ * so one may see ConnectionURLs that look like:
+ * <pre>
+ * amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672?retries='10'&connectdelay='1000''
+ * </pre>
+ *
+ * <p>
+ * <p>
+ * <h3>Extended AMQP 0-10 URL format</h3>
+ * There is a proposal to extend the AMQP 0-10 URL syntax to include user:pass@ style authentication
+ * information, virtual host and extensible name/value options. It also makes the implied extension points of
+ * the original grammar more explicit.
+ * <pre>
+ * amqp_url = "amqp://" [ userinfo "@" ] addr_list [ vhost ]
+ * addr_list = addr *( "," addr )
+ * addr = prot_addr [ options ]
+ * prot_addr = tcp_prot_addr | other_prot_addr
+ * vhost = "/" *pchar [ options ]
+ *
+ * tcp_prot_addr = tcp_id tcp_addr
+ * tcp_id = "tcp:" / "" ; tcp is the default
+ * tcp_addr = [ host [ ":" port ] ]
+ *
+ * other_prot_addr = other_prot_id ":" *pchar
+ * other_prot_id = scheme
+ *
+ * options = "?" option *( ";" option )
+ * option = name "=" value
+ * name = *pchar
+ * value = *pchar
+ * </pre>
+ *
+ * <h3>Incompatibility with AMQP 0-10 format</h3>
+ * This syntax is backward compatible with AMQP 0-10 with one exception: AMQP 0-10 did not have an initial
+ * // after amqp: The justification was that that the // form is only used for URIs with hierarchical structure
+ * <p>
+ * However it's been pointed out that in fact the URL does already specify a 1-level hierarchy of address / vhost.
+ * In the future the hierarchy could be extended to address objects within a vhost such as queues, exchanges etc.
+ * So this proposal adopts amqp:// syntax.
+ * <p>
+ * It's easy to write a backward-compatible parser by relaxing the grammar as follows:
+ * <pre>
+ * amqp_url = "amqp:" [ "//" ] [ userinfo "@" ] addr_list [ vhost ]
+ * </pre>
+ *
+ * <h3>Differences from Qpid M4 Java Connection URL format</h3>
+ * Addresses are at the start of the URL rather than in the "brokerlist" option.
+ * <p>
+ * Option format is ?foo=bar;x=y rather than ?foo='bar'&x='y'. The use of "'" quotes is not common for URI query
+ * strings. The use of "&" as a separator creates problems
+ * <p>
+ * user, pass and clientid are options rather than having a special place at the front of the URL. clientid is
+ * a Qpid proprietary property and user/pass are not relevant in all authentication schemes.
+ * <p>
+ * Qpid M4 Java URLs requires the brokerlist option, so this is an easy way to detect a Qpid M4 URL vs. an
+ * Extended AMQP 0-10 URL and parse accordingly.
+ *
+ * <h3>Options</h3>
+ * Some of the URL forms are fairly limited in terms of options, so it is useful to be able to pass options as
+ * an additional string, though it's important to note that if multiple brokers are supplied in the AMQP 0.10 format
+ * the same options will be applied to all brokers.
+ * <p>
+ * The option format is the same as that of the C++ qpid::messaging Connection class. for example: "{reconnect: true,
+ * tcp-nodelay: true}":
+ * <p>
+ * <table summary="Connection Options" width="100%" border="1"><colgroup><col><col><col></colgroup><thead>
+ * <tr><th>option name</th><th>value type</th><th>semantics</th></tr></thead><tbody>
+ * <tr>
+ * <td><code class="literal">maxprefetch</code></td>
+ * <td>integer</td>
+ * <td>The maximum number of pre-fetched messages per destination.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">sync_publish</code></td>
+ * <td>{'persistent' | 'all'}</td>
+ * <td>A sync command is sent after every persistent message to guarantee that it has been received; if the
+ * value is 'persistent', this is done only for persistent messages.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">sync_ack</code></td>
+ * <td>boolean</td>
+ * <td>A sync command is sent after every acknowledgement to guarantee that it has been received.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">use_legacy_map_msg_format</code></td>
+ * <td>boolean</td>
+ * <td>If you are using JMS Map messages and deploying a new client with any JMS client older than 0.8 release,
+ * you must set this to true to ensure the older clients can understand the map message encoding.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">failover</code></td>
+ * <td>{'roundrobin' | 'singlebroker' | 'nofailover' | 'failover_exchange'}</td>
+ * <td>If roundrobin is selected it will try each broker given in the broker list. If failover_exchange is
+ * selected it connects to the initial broker given in the broker URL and will receive membership updates
+ * via the failover exchange. </td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">cyclecount</code></td>
+ * <td>integer</td>
+ * <td>For roundrobin failover cyclecount is the number of times to loop through the list of available brokers
+ * before failure.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">username</code></td>
+ * <td>string</td>
+ * <td>The username to use when authenticating to the broker.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">password</code></td>
+ * <td>string</td>
+ * <td>The password to use when authenticating to the broker.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">sasl_mechanisms</code></td>
+ * <td>string</td>
+ * <td>The specific SASL mechanisms to use when authenticating to the broker. The value is a space separated list.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">sasl_mechs</code></td>
+ * <td>string</td>
+ * <td>The specific SASL mechanisms to use when authenticating to the broker. The value is a space separated
+ * is a space separated list. This is simply a synonym for sasl_mechanisms above</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">sasl_encryption</code></td>
+ * <td>boolean</td>
+ * <td>If <code class="literal">sasl_encryption='true'</code>, the JMS client attempts to negotiate a security
+ * layer with the broker using GSSAPI to encrypt the connection. Note that for this to happen, GSSAPI must
+ * be selected as the sasl_mech.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">ssl</code></td>
+ * <td>boolean</td>
+ * <td>If <code class="literal">ssl='true'</code>, the JMS client will encrypt the connection using SSL.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">reconnect</code></td>
+ * <td>boolean</td>
+ * <td>Transparently reconnect if the connection is lost.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">reconnect_timeout</code></td>
+ * <td>integer</td>
+ * <td>Total number of seconds to continue reconnection attempts before giving up and raising an exception.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">reconnect_limit</code></td>
+ * <td>integer</td>
+ * <td>Maximum number of reconnection attempts before giving up and raising an exception.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">reconnect_interval_min</code></td>
+ * <td>integer representing time in seconds</td>
+ * <td> Minimum number of seconds between reconnection attempts. The first reconnection attempt is made
+ * immediately; if that fails, the first reconnection delay is set to the value of <code class="literal">
+ * reconnect_interval_min</code>; if that attempt fails, the reconnect interval increases exponentially
+ * until a reconnection attempt succeeds or <code class="literal">reconnect_interval_max</code> is reached.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">reconnect_interval_max</code></td>
+ * <td>integer representing time in seconds</td>
+ * <td>Maximum reconnect interval.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">reconnect_interval</code></td>
+ * <td>integer representing time in seconds</td>
+ * <td>Sets both <code class="literal">reconnection_interval_min</code> and <code class="literal">
+ * reconnection_interval_max</code> to the same value. The default value is 5 seconds</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">heartbeat</code></td>
+ * <td>integer representing time in seconds</td>
+ * <td>Requests that heartbeats be sent every N seconds. If two successive heartbeats are missed the connection is
+ * considered to be lost.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">protocol</code></td>
+ * <td>string</td>
+ * <td>Sets the underlying protocol used. The default option is 'tcp'. To enable ssl, set to 'ssl'. The C++ client
+ * additionally supports 'rdma'. </td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">tcp-nodelay</code></td>
+ * <td>boolean</td>
+ * <td>Set tcp no-delay, i.e. disable Nagle algorithm.</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">sasl_protocol</code></td>
+ * <td>string</td>
+ * <td>Used only for Kerberos. <code class="literal">sasl_protocol</code> must be set to the principal for the
+ * qpidd broker, e.g. <code class="literal">qpidd/</code></td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">sasl_server</code></td>
+ * <td>string</td>
+ * <td>For Kerberos, sasl_mechs must be set to GSSAPI, <code class="literal">sasl_server</code> must be set to
+ * the host for the SASL server, e.g. <code class="literal">sasl.com.</code></td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">trust_store</code></td>
+ * <td>string</td>
+ * <td>path to Keberos trust store</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">trust_store_password</code></td>
+ * <td>string</td>
+ * <td>Kerberos trust store password</td>
+ * </tr>
+ * <tr>
+ * <td><code class="key_store</code></td>
+ * <td>string</td>
+ * <td>path to Kerberos key store </td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">key_store_password</code></td>
+ * <td>string</td>
+ * <td>Kerberos key store password</td>
+ * </tr>
+ * <tr>
+ * <td><code class="literal">ssl_cert_alias</code></td>
+ * <td>string</td>
+ * <td>If multiple certificates are present in the keystore, the alias will be used to extract the correct
+ * certificate.</td>
+ * </tr>
+ * </tbody></table>
+ *
+ * <h3>Other features of this class</h3>
+ * Whilst it is generally the norm to use JNDI to specify Connections, Destinations etc. it is also often quite useful
+ * to specify Connections programmatically, for example when writing a tool one may wish to specify the broker via the
+ * command line to enable the tool to connect to different broker instances.
+ * To facilitate this this class provides a basic createConnection() method that takes a URL and returns a JMS
+ * Connection.
+ *
+ * @author Fraser Adams
+ */
+public final class ConnectionHelper
+{
+ private static final Logger _log = LoggerFactory.getLogger(ConnectionHelper.class);
+
+ /**
+ * Make constructor private as the class comprises only static helper methods.
+ */
+ private ConnectionHelper()
+ {
+ }
+
+ /**
+ * Create a ConnectionURL from the proposed Extended AMQP 0.10 URL format. This is experimental and may or may
+ * not work. Options are assumed to be the same as the Java Connection URL, which will probably not be the case
+ * if this URL form is ultimately adopted. For example the example URLs have "amqp://host1,host2?retry=2,host3"
+ * whereas the Java Connection URL uses &retries=2
+ *
+ * I'm not overly keen on this code it looks pretty inelegant and I'm slightly embarrassed by it, but it
+ * is really just an experiment.
+ *
+ * @param url the input URL.
+ * @param username the username.
+ * @param password the password.
+ * @return a String containing the Java Connection URL.
+ */
+ private static String parseExtendedAMQPURL(String url, String username, String password)
+ {
+ String vhost = ""; // Specifying an empty vhost uses default Virtual Host.
+ String urlOptions = "";
+ String brokerList = "";
+
+ url = url.substring(7); // Chop off "amqp://"
+ String[] split = url.split("@"); // First break out the userinfo if present
+ String remainder = split[0];
+ if (split.length == 2)
+ { // Extract username and password from the userinfo field
+ String[] userinfo = split[0].split(":");
+ remainder = split[1];
+
+ username = userinfo[0];
+ if (userinfo.length == 2)
+ {
+ password = userinfo[1];
+ }
+ }
+
+ // Replace foo=baz with foo='baz'. There's probably a more elegant way to do this using a fancy
+ // regex, but unfortunately I'm not terribly good at regexes so this is the brute force approach :-(
+ // OTOH it's probably more readable and obvious than a regex to do the same thing would be.
+ split = remainder.split("=");
+ StringBuilder buf = new StringBuilder(split[0]);
+ for (int i = 1; i < split.length; i++)
+ {
+ String substring = "='" + split[i];
+ if (substring.contains(";"))
+ {
+ substring = substring.replaceFirst(";", "'&"); // Note we also replace the option separator here
+ }
+ else if (substring.contains("/"))
+ {
+ substring = substring.replaceFirst("/", "'/");
+ }
+ else if (substring.contains(","))
+ {
+ substring = substring.replaceFirst(",", "',");
+ }
+ else
+ {
+ substring = substring + "'";
+ }
+ buf.append(substring);
+ }
+ remainder = buf.toString();
+
+ // Now split into addrList and vhost parts (see Javadoc for the grammar of this URL format)
+ split = remainder.split("/"); // vhost starts with a mandatory '/' character
+ String[] addrSplit = split[0].split(","); // prot_addrs are comma separated
+ boolean firstBroker = true;
+ buf = new StringBuilder();
+ for (String broker : addrSplit)
+ { // Iterate through the address list creating brokerList style URLs
+ broker = broker.trim();
+ String protocol = "tcp"; // set default protocol
+ String[] components = broker.split(":");
+
+ // Note protocols other than tcp and vm are not supported by the Connection URL so the results
+ // are pretty much undefined if other protocols are passed on the input URL.
+ if (components.length == 1)
+ { // Assume protocol = tcp and broker = hostname
+ }
+ else if (components.length == 2)
+ { // Probably host:port but could be some other protocol in and Extended AMQP 0.10 URL
+ try
+ { // Somewhat ugly, but effective test to check if the second component is an integer
+ Integer.parseInt(components[1]);
+ // If the above succeeds the components are likely host:port
+ broker = components[0] + ":" + components[1];
+ }
+ catch (NumberFormatException nfe)
+ { // If the second component isn't an integer then it's likely a wacky protocol...
+ protocol = components[0];
+ broker = components[1];
+ }
+ }
+ else if (components.length == 3)
+ {
+ protocol = components[0];
+ broker = components[1] + ":" + components[2];
+ }
+
+ if (firstBroker)
+ {
+ buf.append(protocol + "://" + broker);
+ }
+ else
+ { // https://cwiki.apache.org/qpid/connection-url-format.html says "A minimum of one broker url is
+ // required additional URLs are semi-colon(';') delimited."
+ buf.append(";" + protocol + "://" + broker);
+ }
+ firstBroker = false;
+ }
+ brokerList = "'" + buf.toString() + "'";
+
+ if (split.length == 2)
+ { // Extract the vhost and any connection level options
+ vhost = split[1];
+ String[] split2 = vhost.split("\\?"); // Look for options
+ vhost = split2[0];
+ if (split2.length == 2)
+ {
+ urlOptions = "&" + split2[1];
+ }
+ }
+
+ String connectionURL = "amqp://" + username + ":" + password + "@QpidJMS/" + vhost + "?brokerlist=" +
+ brokerList + urlOptions;
+ return connectionURL;
+ }
+
+ /**
+ * If no explicit username is supplied then explicitly set sasl mechanism to ANONYMOUS. If this isn't done
+ * The default is PLAIN which causes the broker to fail with "warning Failed to retrieve sasl username".
+ *
+ * @param username the previously extracted username.
+ * @param brokerListOptions the brokerList options extracted so far.
+ * @return the brokerList options adjusted with sasl_mechs='ANONYMOUS' if no username has been supplied.
+ */
+ private static String adjustBrokerListOptions(final String username, final String brokerListOptions)
+ {
+ if (username.equals(""))
+ {
+ if (brokerListOptions.equals(""))
+ {
+ return "?sasl_mechs='ANONYMOUS'";
+ }
+ else
+ {
+ if (brokerListOptions.contains("sasl_mechs"))
+ {
+ return brokerListOptions;
+ }
+ else
+ {
+ return brokerListOptions + "&sasl_mechs='ANONYMOUS'";
+ }
+ }
+ }
+ else
+ {
+ return brokerListOptions;
+ }
+ }
+
+ /**
+ * Create a ConnectionURL from the input "generic" URL.
+ *
+ * @param url the input URL.
+ * @param username the username.
+ * @param password the password.
+ * @param urlOptions the pre-parsed set of connection level options.
+ * @param brokerListOptions the pre-parsed set of specific brokerList options.
+ * @return a String containing the Java Connection URL.
+ */
+ private static String parseURL(String url, String username, String password,
+ String urlOptions, String brokerListOptions)
+ {
+ if (url.startsWith("amqp://"))
+ { // Somewhat experimental. This new format is only a "proposed" format
+ return parseExtendedAMQPURL(url, username, password);
+ }
+
+ String vhost = ""; // Specifying an empty vhost uses default Virtual Host.
+ String brokerList = "";
+ if (url.startsWith("amqp:"))
+ { // AMQP 0.10 URL format
+ url = url.substring(5); // Chop off "amqp:"
+ String[] addrSplit = url.split(","); // prot_addrs are comma separated
+ boolean firstBroker = true;
+ brokerListOptions = adjustBrokerListOptions(username, brokerListOptions);
+ StringBuilder buf = new StringBuilder();
+ for (String broker : addrSplit)
+ { // Iterate through the address list creating brokerList style URLs
+ broker = broker.trim();
+ if (broker.startsWith("tcp:"))
+ { // Only tcp is supported in an AMQP 0.10 prot_addr so we *should* only have to account for
+ // a "tcp:" prefix when normalising broker URLs
+ broker = broker.substring(4); // Chop off "tcp:"
+ }
+
+ if (firstBroker)
+ {
+ buf.append("tcp://" + broker + brokerListOptions);
+ }
+ else
+ { // https://cwiki.apache.org/qpid/connection-url-format.html says "A minimum of one broker url is
+ // required additional URLs are semi-colon(';') delimited."
+ buf.append(";tcp://" + broker + brokerListOptions);
+ }
+ firstBroker = false;
+ }
+ brokerList = "'" + buf.toString() + "'";
+ }
+ else if (url.contains("@"))
+ { // BrokerURL format
+ String[] split = url.split("@");
+ url = split[1];
+
+ split = split[0].split("/");
+ username = split[0];
+
+ if (split.length == 2)
+ {
+ password = split[1];
+ }
+
+ brokerListOptions = adjustBrokerListOptions(username, brokerListOptions);
+ brokerList = "'tcp://" + url + brokerListOptions + "'";
+ }
+ else
+ { // Basic host:port format
+ brokerListOptions = adjustBrokerListOptions(username, brokerListOptions);
+ brokerList = "'tcp://" + url + brokerListOptions + "'";
+ }
+
+ String connectionURL = "amqp://" + username + ":" + password + "@QpidJMS/" + vhost + "?brokerlist=" +
+ brokerList + urlOptions;
+ return connectionURL;
+ }
+
+
+ /**
+ * Creates a Java Connection URL from one of the other supported URL formats.
+ *
+ * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Connection URL (the latter is simply
+ * returned untouched).
+ * @return a String containing the Java Connection URL.
+ */
+ public static String createConnectionURL(String url)
+ {
+ return createConnectionURL(url, null);
+ }
+
+ /**
+ * Creates a Java Connection URL from one of the other supported URL formats plus options.
+ *
+ * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Connection URL (the latter is simply
+ * returned untouched).
+ * @param opts a String containing the options encoded using the same form as the C++ qpid::messaging
+ * Connection class.
+ * @return a String containing the Java Connection URL.
+ */
+ public static String createConnectionURL(String url, String opts)
+ {
+ // This method is actually mostly about parsing the options, when the options are extracted it delegates
+ // to parseURL() to do the actual URL parsing.
+
+ // If a Java Connection URL has been passed in we simply return it.
+ if (url.startsWith("amqp://") && url.contains("brokerlist"))
+ {
+ return url;
+ }
+
+ // Initialise options to default values
+ String username = "";
+ String password = "";
+ String urlOptions = "";
+ String brokerListOptions = "";
+
+ // Get options from option String
+ if (opts != null && opts.startsWith("{") && opts.endsWith("}"))
+ {
+ // Connection URL Options
+ String maxprefetch = "";
+ String sync_publish = "";
+ String sync_ack = "";
+ String use_legacy_map_msg_format = "";
+ String failover = "";
+
+ // Broker List Options
+ String heartbeat = "";
+ String retries = "";
+ String connectdelay = "";
+ String connecttimeout = "";
+
+ String tcp_nodelay = "";
+
+ String sasl_mechs = "";
+ String sasl_encryption = "";
+ String sasl_protocol = "";
+ String sasl_server = "";
+
+ String ssl = "";
+ String ssl_verify_hostname = "";
+ String ssl_cert_alias = "";
+
+ String trust_store = "";
+ String trust_store_password = "";
+ String key_store = "";
+ String key_store_password = "";
+
+ Map options = new AddressParser(opts).map();
+
+ if (options.containsKey("maxprefetch"))
+ {
+ maxprefetch = "&maxprefetch='" + options.get("maxprefetch").toString() + "'";
+ }
+
+ if (options.containsKey("sync_publish"))
+ {
+ sync_publish = "&sync_publish='" + options.get("sync_publish").toString() + "'";
+ }
+
+ if (options.containsKey("sync_ack"))
+ {
+ sync_ack = "&sync_ack='" + options.get("sync_ack").toString() + "'";
+ }
+
+ if (options.containsKey("use_legacy_map_msg_format"))
+ {
+ use_legacy_map_msg_format = "&use_legacy_map_msg_format='" +
+ options.get("use_legacy_map_msg_format").toString() + "'";
+ }
+
+ if (options.containsKey("failover"))
+ {
+ if (options.containsKey("cyclecount"))
+ {
+ failover = "&failover='" + options.get("failover").toString() + "?cyclecount='" +
+ options.get("cyclecount").toString() + "''";
+ }
+ else
+ {
+ failover = "&failover='" + options.get("failover").toString() + "'";
+ }
+ }
+
+ if (options.containsKey("username"))
+ {
+ username = options.get("username").toString();
+ }
+
+ if (options.containsKey("password"))
+ {
+ password = options.get("password").toString();
+ }
+
+ if (options.containsKey("reconnect"))
+ {
+ String value = options.get("reconnect").toString();
+ if (value.equalsIgnoreCase("true"))
+ {
+ retries = "&retries='" + Integer.MAX_VALUE + "'";
+ connectdelay = "&connectdelay='5000'";
+ }
+ }
+
+ if (options.containsKey("reconnect_limit"))
+ {
+ retries = "&retries='" + options.get("reconnect_limit").toString() + "'";
+ }
+
+ if (options.containsKey("reconnect_interval"))
+ {
+ connectdelay = "&connectdelay='" + options.get("reconnect_interval").toString() + "000'";
+ }
+
+ if (options.containsKey("reconnect_interval_min"))
+ {
+ connectdelay = "&connectdelay='" + options.get("reconnect_interval_min").toString() + "000'";
+ }
+
+ if (options.containsKey("reconnect_interval_max"))
+ {
+ connectdelay = "&connectdelay='" + options.get("reconnect_interval_max").toString() + "000'";
+ }
+
+ if (options.containsKey("reconnect_timeout"))
+ {
+ connecttimeout = "&connecttimeout='" + options.get("reconnect_timeout").toString() + "000'";
+ }
+
+ if (options.containsKey("heartbeat"))
+ {
+ heartbeat = "&heartbeat='" + options.get("heartbeat").toString() + "'";
+ }
+
+ if (options.containsKey("tcp-nodelay"))
+ {
+ tcp_nodelay = "&tcp_nodelay='" + options.get("tcp-nodelay").toString() + "'";
+ }
+
+ if (options.containsKey("sasl_mechanisms"))
+ {
+ sasl_mechs = "&sasl_mechs='" + options.get("sasl_mechanisms").toString() + "'";
+ }
+
+ if (options.containsKey("sasl_mechs"))
+ {
+ sasl_mechs = "&sasl_mechs='" + options.get("sasl_mechs").toString() + "'";
+ }
+
+ if (options.containsKey("sasl_encryption"))
+ {
+ sasl_encryption = "&sasl_encryption='" + options.get("sasl_encryption").toString() + "'";
+ }
+
+ if (options.containsKey("sasl_protocol"))
+ {
+ sasl_protocol = "&sasl_protocol='" + options.get("sasl_protocol").toString() + "'";
+ }
+
+ if (options.containsKey("sasl_server"))
+ {
+ sasl_server = "&sasl_server='" + options.get("sasl_server").toString() + "'";
+ }
+
+ if (options.containsKey("trust_store"))
+ {
+ trust_store = "&trust_store='" + options.get("trust_store").toString() + "'";
+ }
+
+ if (options.containsKey("trust_store_password"))
+ {
+ trust_store_password = "&trust_store_password='" + options.get("trust_store_password").toString() + "'";
+ }
+
+ if (options.containsKey("key_store"))
+ {
+ key_store = "&key_store='" + options.get("key_store").toString() + "'";
+ }
+
+ if (options.containsKey("key_store_password"))
+ {
+ key_store_password = "&key_store_password='" + options.get("key_store_password").toString() + "'";
+ }
+
+ if (options.containsKey("protocol"))
+ {
+ String value = options.get("protocol").toString();
+ if (value.equalsIgnoreCase("ssl"))
+ {
+ ssl = "&ssl='true'";
+ if (options.containsKey("ssl_verify_hostname"))
+ {
+ ssl_verify_hostname = "&ssl_verify_hostname='" + options.get("ssl_verify_hostname").toString() + "'";
+ }
+
+ if (options.containsKey("ssl_cert_alias"))
+ {
+ ssl_cert_alias = "&ssl_cert_alias='" + options.get("ssl_cert_alias").toString() + "'";
+ }
+ }
+ }
+
+ urlOptions = maxprefetch + sync_publish + sync_ack + use_legacy_map_msg_format + failover;
+
+ brokerListOptions = heartbeat + retries + connectdelay + connecttimeout + tcp_nodelay +
+ sasl_mechs + sasl_encryption + sasl_protocol + sasl_server +
+ ssl + ssl_verify_hostname + ssl_cert_alias +
+ trust_store + trust_store_password + key_store + key_store_password;
+
+ if (brokerListOptions.startsWith("&"))
+ {
+ brokerListOptions = "?" + brokerListOptions.substring(1);
+ }
+ }
+
+ return parseURL(url, username, password, urlOptions, brokerListOptions);
+ }
+
+ /**
+ * Creates a JMS Connection from one of the supported URL formats.
+ *
+ * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Connection URL.
+ * @return a javax.jms.Connection.
+ */
+ public static Connection createConnection(String url)
+ {
+ return createConnection(url, null);
+ }
+
+ /**
+ * Creates a JMS Connection from one of the supported URL formats plus options.
+ *
+ * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Connection URL.
+ * @param opts a String containing the options encoded using the same form as the C++ qpid::messaging
+ * Connection class.
+ * @return a javax.jms.Connection.
+ */
+ public static Connection createConnection(String url, String opts)
+ {
+ String connectionUrl = createConnectionURL(url, opts);
+ _log.info("ConnectionHelper.createConnection() {}", connectionUrl);
+
+ // Initialise JNDI names etc into properties
+ Properties props = new Properties();
+ props.setProperty("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
+ props.setProperty("connectionfactory.ConnectionFactory", connectionUrl);
+
+ Connection connection = null;
+ try
+ {
+ Context jndi = new InitialContext(props);
+ ConnectionFactory connectionFactory = (ConnectionFactory)jndi.lookup("ConnectionFactory");
+ connection = connectionFactory.createConnection();
+ }
+ catch (NamingException ne)
+ {
+ _log.info("NamingException {} caught in createConnection()", ne.getMessage());
+ }
+ catch (JMSException jmse)
+ {
+ _log.info("JMSException {} caught in createConnection()", jmse.getMessage());
+ }
+
+ return connection;
+ }
+}
+
diff --git a/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/GetOpt.java b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/GetOpt.java
new file mode 100644
index 0000000000..a99ced9682
--- /dev/null
+++ b/qpid/tools/src/java/src/main/java/org/apache/qpid/qmf2/util/GetOpt.java
@@ -0,0 +1,208 @@
+/*
+ *
+ * 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.qmf2.util;
+
+// Misc Imports
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Basic Java port of the python getopt function.
+ *
+ * Takes a standard args String array plus short form and long form options lists.
+ * Searches the args for options and any option arguments and stores these in optList
+ * any remaining args are stored in encArgs.
+ *
+ * <p>
+ * Example usage (paraphrased from QpidConfig):
+ * <pre>
+ * String[] longOpts = {"help", "durable", "cluster-durable", "bindings", "broker-addr=", "file-count=",
+ * "file-size=", "max-queue-size=", "max-queue-count=", "limit-policy=",
+ * "order=", "sequence", "ive", "generate-queue-events=", "force", "force-if-not-empty",
+ * "force-if-used", "alternate-exchange=", "passive", "timeout=", "file=", "flow-stop-size=",
+ * "flow-resume-size=", "flow-stop-count=", "flow-resume-count=", "argument="};
+ *
+ * try
+ * {
+ * GetOpt getopt = new GetOpt(args, "ha:bf:", longOpts);
+ * List<String[]> optList = getopt.getOptList();
+ * String[] cargs = {};
+ * cargs = getopt.getEncArgs().toArray(cargs);
+ *
+ * for (String[] opt : optList)
+ * {
+ * //System.out.println(opt[0] + ":" + opt[1]);
+ * if (opt[0].equals("-a") || opt[0].equals("--broker-addr"))
+ * {
+ * _host = opt[1];
+ * }
+ * // Just a sample - more parsing would follow....
+ * }
+ *
+ * int nargs = cargs.length;
+ * if (nargs == 0)
+ * {
+ * overview();
+ * }
+ * else
+ * {
+ * String cmd = cargs[0];
+ * String modifier = "";
+ *
+ * if (nargs > 1)
+ * {
+ * modifier = cargs[1];
+ * }
+ *
+ * if (cmd.equals("exchanges"))
+ * {
+ * if (_recursive)
+ * {
+ * exchangeListRecurse(modifier);
+ * }
+ * else
+ * {
+ * exchangeList(modifier);
+ * }
+ * }
+ * // Just a sample - more parsing would follow....
+ * }
+ * }
+ * catch (IllegalArgumentException e)
+ * {
+ * System.err.println(e.toString());
+ * usage();
+ * }
+ * </pre>
+ *
+ * @author Fraser Adams
+ */
+public final class GetOpt
+{
+ private List<String[]> _optList = new ArrayList<String[]>();
+ private List<String> _encArgs = new ArrayList<String>();
+
+ /**
+ * Returns the options and option arguments as a list containing a String array. The first element of the array
+ * contains the option and the second contains any arguments if present.
+ *
+ * @return the options and option arguments
+ */
+ public List<String[]> getOptList()
+ {
+ return _optList;
+ }
+
+ /**
+ * Returns any remaining arguments. This is any argument from a command line that doesn't begin "--" or "-".
+ *
+ * @return any remaining arguments not made available by getOptList().
+ */
+ public List<String> getEncArgs()
+ {
+ return _encArgs;
+ }
+
+ /**
+ * Takes a standard args String array plus short form and long form options lists.
+ * Searches the args for options and any option arguments and stores these in optList
+ * any remaining args are stored in encArgs.
+ *
+ * @param args standard arg String array
+ * @param opts short form option list of the form "ab:cd:" where b and d are options with arguments.
+ * @param longOpts long form option list as an array of strings. "option=" signifies an options with arguments.
+ */
+ public GetOpt(String[] args, String opts, String[] longOpts) throws IllegalArgumentException
+ {
+ int argslength = args.length;
+ for (int i = 0; i < argslength; i++)
+ {
+ String arg = args[i];
+ if (arg.startsWith("--"))
+ {
+ String extractedOption = arg.substring(2);
+ int nargs = _optList.size();
+ for (String j : longOpts)
+ {
+ String k = j.substring(0, j.length() - 1);
+ if (j.equals(extractedOption) || k.equals(extractedOption))
+ { // Handle where option and value are space separated
+ String arg0 = arg;
+ String arg1 = "";
+ if (i < argslength - 1 && k.equals(extractedOption))
+ {
+ i++;
+ arg1 = args[i];
+ }
+ String[] option = {arg0, arg1};
+ _optList.add(option);
+ }
+ else
+ { // Handle where option and value are separated by '='
+ String[] split = arg.split("=", 2); // Split on the first occurrence of '='
+ String arg0 = split[0];
+ String arg1 = "";
+ if (split.length == 2)
+ {
+ j = j.substring(0, j.length() - 1);
+ arg1 = split[1];
+ }
+
+ if (arg0.substring(2).equals(j))
+ {
+ String[] option = {arg0, arg1};
+ _optList.add(option);
+ }
+ }
+ }
+
+ if (nargs == _optList.size())
+ {
+ throw new IllegalArgumentException("Unknown Option " + arg);
+ }
+ }
+ else if (arg.startsWith("-"))
+ {
+ String extractedOption = arg.substring(1);
+ int index = opts.indexOf(extractedOption);
+ if (index++ != -1)
+ {
+ String arg1 = "";
+ if (i < argslength - 1 && index < opts.length() && opts.charAt(index) == ':')
+ {
+ i++;
+ arg1 = args[i];
+ }
+ String[] option = {arg, arg1};
+ _optList.add(option);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown Option " + arg);
+ }
+ }
+ else
+ {
+ _encArgs.add(arg);
+ }
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/patch/java/AMQMessageDelegate_0_10.java b/qpid/tools/src/java/src/patch/java/AMQMessageDelegate_0_10.java
new file mode 100644
index 0000000000..9f5217d5db
--- /dev/null
+++ b/qpid/tools/src/java/src/patch/java/AMQMessageDelegate_0_10.java
@@ -0,0 +1,958 @@
+/*
+ *
+ * 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.client.message;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageNotWriteableException;
+import javax.jms.Session;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.AMQPInvalidClassException;
+import org.apache.qpid.collections.ReferenceMap;
+import org.apache.qpid.client.AMQDestination;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQSession_0_10;
+import org.apache.qpid.client.CustomJMSXProperty;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.jms.Message;
+import org.apache.qpid.transport.DeliveryProperties;
+import org.apache.qpid.transport.ExchangeQueryResult;
+import org.apache.qpid.transport.Future;
+import org.apache.qpid.transport.Header;
+import org.apache.qpid.transport.MessageDeliveryMode;
+import org.apache.qpid.transport.MessageDeliveryPriority;
+import org.apache.qpid.transport.MessageProperties;
+import org.apache.qpid.transport.ReplyTo;
+
+/**
+ * This extends AbstractAMQMessageDelegate which contains common code between
+ * both the 0_8 and 0_10 Message types.
+ *
+ */
+public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate
+{
+ private static final Map<ReplyTo, Destination> _destinationCache = Collections.synchronizedMap(new ReferenceMap());
+
+ public static final String JMS_TYPE = "x-jms-type";
+
+
+ private boolean _readableProperties = false;
+
+ private Destination _destination;
+
+
+ private MessageProperties _messageProps;
+ private DeliveryProperties _deliveryProps;
+ /** If the acknowledge mode is CLIENT_ACKNOWLEDGE the session is required */
+ private AMQSession _session;
+ private final long _deliveryTag;
+
+
+ protected AMQMessageDelegate_0_10()
+ {
+ this(new MessageProperties(), new DeliveryProperties(), -1);
+ _readableProperties = false;
+ }
+
+ protected AMQMessageDelegate_0_10(MessageProperties messageProps, DeliveryProperties deliveryProps, long deliveryTag)
+ {
+ _messageProps = messageProps;
+ _deliveryProps = deliveryProps;
+ _deliveryTag = deliveryTag;
+ _readableProperties = (_messageProps != null);
+
+ AMQDestination dest;
+
+ dest = generateDestination(new AMQShortString(_deliveryProps.getExchange()),
+ new AMQShortString(_deliveryProps.getRoutingKey()));
+ setJMSDestination(dest);
+ }
+
+ /**
+ * Use the 0-10 ExchangeQuery call to validate the exchange type.
+ *
+ * This is used primarily to provide the correct JMSDestination value.
+ *
+ * The query is performed synchronously iff the map exchange is not already
+ * present in the exchange Map.
+ *
+ * @param header The message headers, from which the exchange name can be extracted
+ * @param session The 0-10 session to use to call ExchangeQuery
+ */
+ public static void updateExchangeTypeMapping(Header header, org.apache.qpid.transport.Session session)
+ {
+ DeliveryProperties deliveryProps = header.get(DeliveryProperties.class);
+ if (deliveryProps != null)
+ {
+ String exchange = deliveryProps.getExchange();
+
+ if (exchange != null && !exchangeMapContains(exchange))
+ {
+ Future<ExchangeQueryResult> future =
+ session.exchangeQuery(exchange.toString());
+ ExchangeQueryResult res = future.get();
+
+ updateExchangeType(exchange, res.getType());
+ }
+ }
+ }
+
+
+ public String getJMSMessageID() throws JMSException
+ {
+ UUID id = _messageProps.getMessageId();
+ return id == null ? null : "ID:" + id;
+ }
+
+ public void setJMSMessageID(String messageId) throws JMSException
+ {
+ if(messageId == null)
+ {
+ _messageProps.clearMessageId();
+ }
+ else
+ {
+ if(messageId.startsWith("ID:"))
+ {
+ try
+ {
+ _messageProps.setMessageId(UUID.fromString(messageId.substring(3)));
+ }
+ catch(IllegalArgumentException ex)
+ {
+ throw new JMSException("MessageId '"+messageId+"' is not of the correct format, it must be ID: followed by a UUID");
+ }
+ }
+ else
+ {
+ throw new JMSException("MessageId '"+messageId+"' is not of the correct format, it must be ID: followed by a UUID");
+ }
+ }
+ }
+
+ public void setJMSMessageID(UUID messageId) throws JMSException
+ {
+ if(messageId == null)
+ {
+ _messageProps.clearMessageId();
+ }
+ else
+ {
+ _messageProps.setMessageId(messageId);
+ }
+ }
+
+
+ public long getJMSTimestamp() throws JMSException
+ {
+ return _deliveryProps.getTimestamp();
+ }
+
+ public void setJMSTimestamp(long timestamp) throws JMSException
+ {
+ _deliveryProps.setTimestamp(timestamp);
+ }
+
+ public byte[] getJMSCorrelationIDAsBytes() throws JMSException
+ {
+ return _messageProps.getCorrelationId();
+ }
+
+ public void setJMSCorrelationIDAsBytes(byte[] bytes) throws JMSException
+ {
+ _messageProps.setCorrelationId(bytes);
+ }
+
+ public void setJMSCorrelationID(String correlationId) throws JMSException
+ {
+
+ setJMSCorrelationIDAsBytes(correlationId == null ? null : correlationId.getBytes());
+ }
+
+ public String getJMSCorrelationID() throws JMSException
+ {
+
+ byte[] correlationIDAsBytes = getJMSCorrelationIDAsBytes();
+ return correlationIDAsBytes == null ? null : new String(correlationIDAsBytes);
+ }
+
+ public Destination getJMSReplyTo()
+ {
+ ReplyTo replyTo = _messageProps.getReplyTo();
+
+ if (replyTo == null)
+ {
+ return null;
+ }
+ else
+ {
+ Destination dest = _destinationCache.get(replyTo);
+ if (dest == null)
+ {
+ String exchange = replyTo.getExchange();
+ String routingKey = replyTo.getRoutingKey();
+
+ dest = generateDestination(exchange == null ? null : new AMQShortString(exchange),
+ routingKey == null ? null : new AMQShortString(routingKey));
+
+
+
+
+
+ _destinationCache.put(replyTo, dest);
+ }
+
+ return dest;
+ }
+ }
+
+ public void setJMSReplyTo(Destination destination) throws JMSException
+ {
+ if (destination == null)
+ {
+ _messageProps.setReplyTo(null);
+ return;
+ }
+
+ if (!(destination instanceof AMQDestination))
+ {
+ throw new IllegalArgumentException(
+ "ReplyTo destination may only be an AMQDestination - passed argument was type " + destination.getClass());
+ }
+
+ final AMQDestination amqd = (AMQDestination) destination;
+
+ if (amqd.getDestSyntax() == AMQDestination.DestSyntax.ADDR)
+ {
+ try
+ {
+ int type = ((AMQSession_0_10)_session).resolveAddressType(amqd);
+ if (type == AMQDestination.QUEUE_TYPE)
+ {
+ ((AMQSession_0_10)_session).setLegacyFiledsForQueueType(amqd);
+ }
+ else
+ {
+ ((AMQSession_0_10)_session).setLegacyFiledsForTopicType(amqd);
+ }
+ }
+ catch(AMQException ex)
+ {
+ JMSException e = new JMSException("Error occured while figuring out the node type");
+ e.initCause(ex);
+ e.setLinkedException(ex);
+ throw e;
+ }
+ }
+
+ final ReplyTo replyTo = new ReplyTo(amqd.getExchangeName().toString(), amqd.getRoutingKey().toString());
+ _destinationCache.put(replyTo, destination);
+ _messageProps.setReplyTo(replyTo);
+
+ }
+
+ public Destination getJMSDestination() throws JMSException
+ {
+ return _destination;
+ }
+
+ public void setJMSDestination(Destination destination)
+ {
+ _destination = destination;
+ }
+
+ public void setContentType(String contentType)
+ {
+ _messageProps.setContentType(contentType);
+ }
+
+ public String getContentType()
+ {
+ return _messageProps.getContentType();
+ }
+
+ public void setEncoding(String encoding)
+ {
+ if(encoding == null || encoding.length() == 0)
+ {
+ _messageProps.clearContentEncoding();
+ }
+ else
+ {
+ _messageProps.setContentEncoding(encoding);
+ }
+ }
+
+ public String getEncoding()
+ {
+ return _messageProps.getContentEncoding();
+ }
+
+ public String getReplyToString()
+ {
+ Destination replyTo = getJMSReplyTo();
+ if(replyTo != null)
+ {
+ return ((AMQDestination)replyTo).toURL();
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+
+ public int getJMSDeliveryMode() throws JMSException
+ {
+
+ MessageDeliveryMode deliveryMode = _deliveryProps.getDeliveryMode();
+ if(deliveryMode != null)
+ {
+ switch(deliveryMode)
+ {
+ case PERSISTENT :
+ return DeliveryMode.PERSISTENT;
+ case NON_PERSISTENT:
+ return DeliveryMode.NON_PERSISTENT;
+ default:
+ throw new JMSException("Unknown Message Delivery Mode: " + _deliveryProps.getDeliveryMode());
+ }
+ }
+ else
+ {
+ return Message.DEFAULT_DELIVERY_MODE;
+ }
+
+ }
+
+ public void setJMSDeliveryMode(int deliveryMode) throws JMSException
+ {
+ switch(deliveryMode)
+ {
+ case DeliveryMode.PERSISTENT:
+ _deliveryProps.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
+ break;
+ case DeliveryMode.NON_PERSISTENT:
+ _deliveryProps.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
+ break;
+ default:
+ throw new JMSException("Unknown JMS Delivery Mode: " + deliveryMode);
+ }
+
+ }
+
+
+ public String getJMSType() throws JMSException
+ {
+ if(getApplicationHeaders().containsKey(JMS_TYPE))
+ {
+ return getStringProperty(JMS_TYPE);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private Map<String, Object> getApplicationHeaders()
+ {
+ Map<String, Object> map = _messageProps.getApplicationHeaders();
+ return map == null ? Collections.EMPTY_MAP : map;
+ }
+
+ public void setJMSType(String type) throws JMSException
+ {
+ Map<String, Object> headers = _messageProps.getApplicationHeaders();
+ if(type == null)
+ {
+ if(headers != null)
+ {
+ headers.remove(JMS_TYPE);
+ }
+ }
+ else
+ {
+ if(headers == null)
+ {
+ headers = new HashMap<String,Object>();
+ _messageProps.setApplicationHeaders(headers);
+
+ }
+ headers.put(JMS_TYPE, type);
+ }
+ }
+
+ public long getJMSExpiration() throws JMSException
+ {
+ return _deliveryProps.getExpiration();
+ }
+
+ public void setJMSExpiration(long l) throws JMSException
+ {
+ _deliveryProps.setExpiration(l);
+ }
+
+
+
+ public boolean propertyExists(String propertyName) throws JMSException
+ {
+ return getApplicationHeaders().containsKey(propertyName);
+ }
+
+ public boolean getBooleanProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+
+ Object o = getApplicationHeaders().get(propertyName);
+
+ if(o instanceof Boolean)
+ {
+ return ((Boolean)o).booleanValue();
+ }
+ else if(o instanceof String)
+ {
+ return Boolean.valueOf((String) o).booleanValue();
+ }
+ else if(getApplicationHeaders().containsKey(propertyName))
+ {
+ throw new MessageFormatException("getBooleanProperty(\""+propertyName+"\") failed as value is not boolean: " + o);
+ }
+ else
+ {
+ return Boolean.valueOf(null);
+ }
+ }
+
+ public byte getByteProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ Object o = propertyMap.get(propertyName);
+
+ if(o instanceof Byte)
+ {
+ return ((Byte)o).byteValue();
+ }
+ else if(o instanceof String)
+ {
+ return Byte.valueOf((String) o).byteValue();
+ }
+ else if(getApplicationHeaders().containsKey(propertyName))
+ {
+ throw new MessageFormatException("getByteProperty(\""+propertyName+"\") failed as value is not a byte: " + o);
+ }
+ else
+ {
+ return Byte.valueOf(null);
+ }
+ }
+
+ public short getShortProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ Object o = propertyMap.get(propertyName);
+
+ if(o instanceof Short)
+ {
+ return ((Short)o).shortValue();
+ }
+ else
+ {
+ try
+ {
+ return Short.valueOf(getByteProperty(propertyName));
+ }
+ catch(MessageFormatException e)
+ {
+ throw new MessageFormatException("getShortProperty(\""+propertyName+"\") failed as value is not a short: " + o);
+ }
+ }
+
+
+ }
+
+ public int getIntProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ Object o = propertyMap.get(propertyName);
+
+ if(o instanceof Integer)
+ {
+ return ((Integer)o).intValue();
+ }
+ else
+ {
+ try
+ {
+ return Integer.valueOf(getShortProperty(propertyName));
+ }
+ catch(MessageFormatException e)
+ {
+ throw new MessageFormatException("getIntProperty(\""+propertyName+"\") failed as value is not an int: " + o);
+ }
+
+ }
+ }
+
+ public long getLongProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ Object o = propertyMap.get(propertyName);
+
+ if(o instanceof Long)
+ {
+ return ((Long)o).longValue();
+ }
+ else
+ {
+ try
+ {
+ return Long.valueOf(getIntProperty(propertyName));
+ }
+ catch(MessageFormatException e)
+ {
+ throw new MessageFormatException("getLongProperty(\""+propertyName+"\") failed as value is not a long: " + o);
+ }
+
+ }
+ }
+
+ public float getFloatProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ Object o = propertyMap.get(propertyName);
+
+ if(o instanceof Float)
+ {
+ return ((Float)o).floatValue();
+ }
+ else if(o instanceof String)
+ {
+ return Float.valueOf((String) o).floatValue();
+ }
+ else if(getApplicationHeaders().containsKey(propertyName))
+ {
+ throw new MessageFormatException("getFloatProperty(\""+propertyName+"\") failed as value is not a float: " + o);
+ }
+ else
+ {
+ throw new NullPointerException("No such property: " + propertyName);
+ }
+
+ }
+
+ public double getDoubleProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ Object o = propertyMap.get(propertyName);
+
+ if(o instanceof Double)
+ {
+ return ((Double)o).doubleValue();
+ }
+ else if (o instanceof String)
+ {
+ return Double.valueOf((String)o);
+ }
+ else
+ {
+ try
+ {
+ return Double.valueOf(getFloatProperty(propertyName));
+ }
+ catch(MessageFormatException e)
+ {
+ throw new MessageFormatException("getDoubleProperty(\""+propertyName+"\") failed as value is not a double: " + o);
+ }
+
+ }
+ }
+
+ public String getStringProperty(String propertyName) throws JMSException
+ {
+ if (propertyName.equals(CustomJMSXProperty.JMSXUserID.toString()))
+ {
+ return new String(_messageProps.getUserId());
+ }
+ else
+ {
+ checkPropertyName(propertyName);
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ Object o = propertyMap.get(propertyName);
+
+ if(o instanceof String)
+ {
+ return (String) o;
+ }
+ else if(o == null)
+ {
+ return null;
+ }
+ else if(o.getClass().isArray())
+ {
+ throw new MessageFormatException("getString(\""+propertyName+"\") failed as value of type " + o.getClass()+ " is an array.");
+ }
+ else
+ {
+ return String.valueOf(o);
+ }
+
+ }
+ }
+
+ public Object getObjectProperty(String propertyName) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ Map<String, Object> propertyMap = getApplicationHeaders();
+
+ return propertyMap.get(propertyName);
+
+ }
+
+ public Enumeration getPropertyNames() throws JMSException
+ {
+ return java.util.Collections.enumeration(getApplicationHeaders().keySet());
+ }
+
+ public void setBooleanProperty(String propertyName, boolean b) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, b);
+ }
+
+ public void setByteProperty(String propertyName, byte b) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, b);
+ }
+
+ public void setShortProperty(String propertyName, short i) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, i);
+ }
+
+ public void setIntProperty(String propertyName, int i) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, i);
+ }
+
+ public void setLongProperty(String propertyName, long l) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, l);
+ }
+
+ public void setFloatProperty(String propertyName, float f) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, f);
+ }
+
+ public void setDoubleProperty(String propertyName, double v) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, v);
+ }
+
+ public void setStringProperty(String propertyName, String value) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ setApplicationHeader(propertyName, value);
+
+ if ("x-amqp-0-10.app-id".equals(propertyName)) {
+ _messageProps.setAppId(value.getBytes());
+ }
+ }
+
+ private static final Set<Class> ALLOWED = new HashSet();
+ static
+ {
+ ALLOWED.add(Boolean.class);
+ ALLOWED.add(Byte.class);
+ ALLOWED.add(Short.class);
+ ALLOWED.add(Integer.class);
+ ALLOWED.add(Long.class);
+ ALLOWED.add(Float.class);
+ ALLOWED.add(Double.class);
+ ALLOWED.add(Character.class);
+ ALLOWED.add(String.class);
+ ALLOWED.add(byte[].class);
+ }
+
+ public void setObjectProperty(String propertyName, Object object) throws JMSException
+ {
+ checkPropertyName(propertyName);
+ checkWritableProperties();
+ if (object == null)
+ {
+ throw new MessageFormatException(AMQPInvalidClassException.INVALID_OBJECT_MSG + "null");
+ }
+ else if (!ALLOWED.contains(object.getClass()))
+ {
+ throw new MessageFormatException(AMQPInvalidClassException.INVALID_OBJECT_MSG + object.getClass());
+ }
+ setApplicationHeader(propertyName, object);
+ }
+
+ private void setApplicationHeader(String propertyName, Object object)
+ {
+ Map<String, Object> headers = _messageProps.getApplicationHeaders();
+ if(headers == null)
+ {
+ headers = new HashMap<String,Object>();
+ _messageProps.setApplicationHeaders(headers);
+ }
+ headers.put(propertyName, object);
+ }
+
+ public void removeProperty(String propertyName) throws JMSException
+ {
+ Map<String, Object> headers = _messageProps.getApplicationHeaders();
+ if(headers != null)
+ {
+ headers.remove(propertyName);
+ }
+ }
+
+
+
+ protected void checkWritableProperties() throws MessageNotWriteableException
+ {
+ if (_readableProperties)
+ {
+ throw new MessageNotWriteableException("You need to call clearProperties() to make the message writable");
+ }
+ }
+
+
+ public int getJMSPriority() throws JMSException
+ {
+ MessageDeliveryPriority messageDeliveryPriority = _deliveryProps.getPriority();
+ return messageDeliveryPriority == null ? Message.DEFAULT_PRIORITY : messageDeliveryPriority.getValue();
+ }
+
+ public void setJMSPriority(int i) throws JMSException
+ {
+ _deliveryProps.setPriority(MessageDeliveryPriority.get((short)i));
+ }
+
+ public void clearProperties() throws JMSException
+ {
+ if(!getApplicationHeaders().isEmpty())
+ {
+ getApplicationHeaders().clear();
+ }
+
+ _readableProperties = false;
+ }
+
+
+ public void acknowledgeThis() throws JMSException
+ {
+ // the JMS 1.1 spec says in section 3.6 that calls to acknowledge are ignored when client acknowledge
+ // is not specified. In our case, we only set the session field where client acknowledge mode is specified.
+ if (_session != null && _session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
+ {
+ if (_session.getAMQConnection().isClosed())
+ {
+ throw new javax.jms.IllegalStateException("Connection is already closed");
+ }
+
+ // we set multiple to true here since acknowledgment implies acknowledge of all previous messages
+ // received on the session
+ _session.acknowledgeMessage(_deliveryTag, true);
+ }
+ }
+
+ public void acknowledge() throws JMSException
+ {
+ if (_session != null && _session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
+ {
+ _session.acknowledge();
+ }
+ }
+
+
+ /**
+ * The session is set when CLIENT_ACKNOWLEDGE mode is used so that the CHANNEL ACK can be sent when the user calls
+ * acknowledge()
+ *
+ * @param s the AMQ session that delivered this message
+ */
+ public void setAMQSession(AMQSession s)
+ {
+ _session = s;
+ }
+
+ public AMQSession getAMQSession()
+ {
+ return _session;
+ }
+
+ /**
+ * Get the AMQ message number assigned to this message
+ *
+ * @return the message number
+ */
+ public long getDeliveryTag()
+ {
+ return _deliveryTag;
+ }
+
+
+
+
+
+
+ protected void checkPropertyName(CharSequence propertyName)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("Property name must not be null");
+ }
+ else if (propertyName.length() == 0)
+ {
+ throw new IllegalArgumentException("Property name must not be the empty string");
+ }
+
+ checkIdentiferFormat(propertyName);
+ }
+
+ protected void checkIdentiferFormat(CharSequence propertyName)
+ {
+// JMS requirements 3.5.1 Property Names
+// Identifiers:
+// - An identifier is an unlimited-length character sequence that must begin
+// with a Java identifier start character; all following characters must be Java
+// identifier part characters. An identifier start character is any character for
+// which the method Character.isJavaIdentifierStart returns true. This includes
+// '_' and '$'. An identifier part character is any character for which the
+// method Character.isJavaIdentifierPart returns true.
+// - Identifiers cannot be the names NULL, TRUE, or FALSE.
+// Identifiers cannot be NOT, AND, OR, BETWEEN, LIKE, IN, IS, or
+// ESCAPE.
+// Identifiers are either header field references or property references. The
+// type of a property value in a message selector corresponds to the type
+// used to set the property. If a property that does not exist in a message is
+// referenced, its value is NULL. The semantics of evaluating NULL values
+// in a selector are described in Section 3.8.1.2, Null Values.
+// The conversions that apply to the get methods for properties do not
+// apply when a property is used in a message selector expression. For
+// example, suppose you set a property as a string value, as in the
+// following:
+// myMessage.setStringProperty("NumberOfOrders", "2");
+// The following expression in a message selector would evaluate to false,
+// because a string cannot be used in an arithmetic expression:
+// "NumberOfOrders > 1"
+// Identifiers are case sensitive.
+// Message header field references are restricted to JMSDeliveryMode,
+// JMSPriority, JMSMessageID, JMSTimestamp, JMSCorrelationID, and
+// JMSType. JMSMessageID, JMSCorrelationID, and JMSType values may be
+// null and if so are treated as a NULL value.
+
+ if (Boolean.getBoolean("strict-jms"))
+ {
+ // JMS start character
+ if (!(Character.isJavaIdentifierStart(propertyName.charAt(0))))
+ {
+ throw new IllegalArgumentException("Identifier '" + propertyName + "' does not start with a valid JMS identifier start character");
+ }
+
+ // JMS part character
+ int length = propertyName.length();
+ for (int c = 1; c < length; c++)
+ {
+ if (!(Character.isJavaIdentifierPart(propertyName.charAt(c))))
+ {
+ throw new IllegalArgumentException("Identifier '" + propertyName + "' contains an invalid JMS identifier character");
+ }
+ }
+
+ // JMS invalid names
+ if ((propertyName.equals("NULL")
+ || propertyName.equals("TRUE")
+ || propertyName.equals("FALSE")
+ || propertyName.equals("NOT")
+ || propertyName.equals("AND")
+ || propertyName.equals("OR")
+ || propertyName.equals("BETWEEN")
+ || propertyName.equals("LIKE")
+ || propertyName.equals("IN")
+ || propertyName.equals("IS")
+ || propertyName.equals("ESCAPE")))
+ {
+ throw new IllegalArgumentException("Identifier '" + propertyName + "' is not allowed in JMS");
+ }
+ }
+
+ }
+
+
+ public MessageProperties getMessageProperties()
+ {
+ return _messageProps;
+ }
+
+
+ public DeliveryProperties getDeliveryProperties()
+ {
+ return _deliveryProps;
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java
new file mode 100644
index 0000000000..43b6bd9a1d
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java
@@ -0,0 +1,592 @@
+/*
+ *
+ * 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.server.qmf2;
+
+// Misc Imports
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.Agent;
+import org.apache.qpid.qmf2.agent.MethodCallParams;
+import org.apache.qpid.qmf2.agent.MethodCallWorkItem;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+// Java Broker model Imports
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfigurationChangeListener;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Connection;
+import org.apache.qpid.server.model.Consumer;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Publisher;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.Session;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+
+/**
+ * This class implements a QMF2 Agent providing access to the Java broker Management Objects via QMF2 thus
+ * allowing the Java broker to be managed in the same way to the C++ broker.
+ * <p>
+ * The intention is for the QmfManagementAgent to conform to the same Management Schema as the C++ broker
+ * (e.g. as specified in <qpid>/specs/management-schema.xml) in order to provide maximum cohesion between
+ * the to broker implementations, however that's not entirely possible given differences between the underlying
+ * Management models.
+ * <p>
+ * This Plugin attempts to map properties from the Java org.apache.qpid.server.model.* classes to equivalent
+ * properties and statistics in the C++ broker's Management Schema rather than expose them "natively", this is
+ * in order to try and maximise alignment between the two implementations and to try to allow the Java broker
+ * to be managed by the Command Line tools used with the C++ broker such as qpid-config etc. it's also to
+ * enable the Java broker to be accessed via the QMF2 REST API and GUI.
+ *
+ * @author Fraser Adams
+ */
+public class QmfManagementAgent implements ConfigurationChangeListener, QmfEventListener
+{
+ private static final Logger _log = LoggerFactory.getLogger(QmfManagementAgent.class);
+
+ // Set heartbeat interval to 10 seconds. TODO Should probably be config driven, but I *think* that this is
+ // different than "heartbeat.delay" and "heartbeat.timeoutFactor" currently present in the config?
+ private static final int HEARTBEAT_INTERVAL = 10;
+ private Agent _agent = null;
+
+ // The first Connection Object relates to the QmfManagementAgent, we use this flag to avoid mapping that Connection
+ // to a QMF Object thus hiding it from Consoles. This is done to provide consistency with the C++ broker which
+ // also "hides" its own private AMQP Connections, Queues & Bindings.
+ private boolean agentConnection = true;
+
+ private final Broker _broker; // Passed in by Plugin bootstrapping.
+ private final String _defaultVirtualHost; // Pulled from the broker attributes.
+
+ /**
+ * A Map of QmfAgentData keyed by ConfiguredObject. This is mainly used for Management Object "lifecycle management".
+ * In an ideal world the Agent class could retain all information, but I want to track ConfiguredObject state and
+ * use that to create and delete QmfAgentData data, which means I need to be able to *find* the QmfAgentData and
+ * the *official* Agent API doesn't have a public method to query Objects (though the evaluateQuery() method used
+ * by Query Subscriptions could be used, but it's not really a "public API method" so probably best not to use it)
+ * Arguably this is what the AgentExternal subclass of Agent is for whereby queries are handled in the Agent
+ * implementation by handling "(wi.getType() == QUERY)" but the AgentExternal API forces some constructs that are
+ * actually likely to be less efficient, as an example sending a separate queryResponse() for each object forces a
+ * look up of a List of QmfAgentData objects keyed by the consoleHandle for each call. There is also the need to
+ * separately iterate through the List of QmfAgentData objects thus created to create the mapEncoded list needed
+ * for sending via the QMF2 protocol.
+ * <p>
+ * So rather than go through all that faff we simply retain an additional Map as below which allows navigation
+ * between the ConfiguredObject and QmfAgentData. The subclasses of QmfAgentData will contain references to
+ * allow navigation back to the concrete subclasses of ConfiguredObject if necessary.
+ * The capacity of 100 is pretty arbitrary but the default of 16 seems too low for a ManagementAgent.
+ */
+ private Map<ConfiguredObject, QmfAgentData> _objects = new ConcurrentHashMap<ConfiguredObject, QmfAgentData>(100);
+
+ /**
+ * Constructor. Creates the AMQP Connection to the broker and starts the QMF2 Agent.
+ * @param url the Connection URL to be used to construct the AMQP Connection.
+ * @param broker the root Broker Management Object from which the other Management Objects may be obtained.
+ * to work without explicitly setting a Virtual Host, which I think is necessary because the C++ broker and
+ * the python command line tools aren't currently Virtual Host aware (are they?). The intention is to mark
+ * queues and exchanges with [vhost:<vhost-name>/]<object-name> in other words if we want to add things to
+ * the non-default Virtual Host prefix their names with [vhost:<vhost-name>/]. This approach *ought* to allow
+ * non-Virtual Host aware command line tools the ability to add queues/exchanges to a particular vhost.
+ */
+ public QmfManagementAgent(final String url, final Broker broker)
+ {
+ _broker = broker;
+ _defaultVirtualHost = (String)broker.getAttribute("defaultVirtualHost");
+
+ try
+ {
+ // Create the actual JMS Connection. ConnectionHelper allows us to work with a variety of URL
+ // formats so we can abstract away from the somewhat complex Java AMQP URL format.
+ javax.jms.Connection connection = ConnectionHelper.createConnection(url);
+ if (connection == null)
+ {
+ _log.info("QmfManagementAgent Constructor failed due to null AMQP Connection");
+ }
+ else
+ {
+ _agent = new Agent(this, HEARTBEAT_INTERVAL);
+ // Vendor and Product are deliberately set to be the same as for the C++ broker.
+ _agent.setVendor("apache.org");
+ _agent.setProduct("qpidd");
+ _agent.setConnection(connection);
+
+ // Register the schema for the Management Objects. These don't have to be completely populated
+ // the minimum is to register package name and class name for the QmfAgentData.
+ _agent.registerObjectClass(org.apache.qpid.server.qmf2.agentdata.Broker.getSchema());
+ _agent.registerObjectClass(org.apache.qpid.server.qmf2.agentdata.Connection.getSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Connection.getClientConnectSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Connection.getClientDisconnectSchema());
+
+ _agent.registerObjectClass(org.apache.qpid.server.qmf2.agentdata.Exchange.getSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Exchange.getExchangeDeclareSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Exchange.getExchangeDeleteSchema());
+
+ _agent.registerObjectClass(org.apache.qpid.server.qmf2.agentdata.Queue.getSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Queue.getQueueDeclareSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Queue.getQueueDeleteSchema());
+
+ _agent.registerObjectClass(org.apache.qpid.server.qmf2.agentdata.Binding.getSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Binding.getBindSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Binding.getUnbindSchema());
+
+ _agent.registerObjectClass(org.apache.qpid.server.qmf2.agentdata.Subscription.getSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Subscription.getSubscribeSchema());
+ _agent.registerEventClass(org.apache.qpid.server.qmf2.agentdata.Subscription.getUnsubscribeSchema());
+
+ // Initialise QmfAgentData Objects and track changes to the broker Management Objects.
+ registerConfigurationChangeListeners();
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ _log.info("QmfException {} caught in QmfManagementAgent Constructor", qmfe.getMessage());
+ }
+ catch (Exception e)
+ {
+ _log.info("Exception {} caught in QmfManagementAgent Constructor", e.getMessage());
+ }
+ }
+
+ /**
+ * Close the QmfManagementAgent clearing the QMF2 Agent and freeing its resources.
+ */
+ public void close()
+ {
+ if (isConnected())
+ {
+ _agent.destroy();
+ }
+ }
+
+ /**
+ * Returns whether the Agent is connected and running.
+ * @return true if the Agent is connected and running otherwise return false.
+ */
+ public boolean isConnected()
+ {
+ return _agent != null;
+ }
+
+ /**
+ * This method initialises the initial set of QmfAgentData Objects and tracks changes to the broker Management
+ * Objects via the childAdded() method call.
+ */
+ private void registerConfigurationChangeListeners()
+ {
+ childAdded(null, _broker);
+
+ for (VirtualHost vhost : _broker.getVirtualHosts())
+ {
+ // We don't add QmfAgentData VirtualHost objects. Possibly TODO, but it's a bit awkward at the moment
+ // becase (as of Qpid 0.20) the C++ broker doesn't *seem* to do much with them and the command line
+ // tools such as qpid-config don't appear to be VirtualHost aware. A way to stay compatible is to
+ // mark queues, exchanges etc with [vhost:<vhost-name>/]<object-name> (see Constructor comments).
+ vhost.addChangeListener(this);
+
+ for (Connection connection : vhost.getConnections())
+ {
+ childAdded(vhost, connection);
+
+ for (Session session : connection.getSessions())
+ {
+ childAdded(connection, session);
+
+ // session.getSubscriptions() returns null in Qpid 0.23 TODO fix that.
+ if (session.getSubscriptions() != null)
+ {
+ for (Consumer subscription : session.getSubscriptions())
+ {
+ childAdded(session, subscription);
+ }
+ }
+ }
+ }
+
+ // The code blocks for adding Bindings (and adding Queues) contain checks to see if what is being added
+ // relates to Queues or Bindings for the QmfManagementAgent. If they are QmfManagementAgent related
+ // we avoid registering the Object as a QMF Object, in other words we "hide" QmfManagementAgent QMF Objects.
+ // This is done to be consistent with the C++ broker which also "hides" its own Connection, Queue & Binding.
+ for (Exchange exchange : vhost.getExchanges())
+ {
+ childAdded(vhost, exchange);
+
+ for (Binding binding : exchange.getBindings())
+ {
+ String key = binding.getName();
+ if (key.equals("broker") || key.equals("console.request.agent_locate") ||
+ key.startsWith("apache.org:qpidd:") || key.startsWith("TempQueue"))
+ { // Don't add QMF related Bindings in registerConfigurationChangeListeners as those will relate
+ } // to the Agent and we want to "hide" those.
+ else
+ {
+ childAdded(exchange, binding);
+ }
+ }
+ }
+
+ for (Queue queue : vhost.getQueues())
+ {
+ boolean agentQueue = false;
+ for (Binding binding : queue.getBindings())
+ {
+ String key = binding.getName();
+ if (key.equals("broker") || key.equals("console.request.agent_locate") ||
+ key.startsWith("apache.org:qpidd:"))
+ {
+ agentQueue = true;
+ break;
+ }
+ }
+
+ // Don't add QMF related bindings or Queues in registerConfigurationChangeListeners as those will
+ // relate to the Agent itself and we want to "hide" those to be consistent with the C++ Broker.
+ if (!agentQueue)
+ {
+ childAdded(vhost, queue);
+
+ for (Binding binding : queue.getBindings())
+ {
+ childAdded(queue, binding);
+ }
+
+ for (Consumer subscription : queue.getConsumers())
+ {
+ childAdded(queue, subscription);
+ }
+ }
+ }
+ }
+ }
+
+
+ // ************************* ConfigurationChangeListener implementation methods *************************
+
+ /**
+ * ConfigurationChangeListener method called when the state is changed (ignored here).
+ * @param object the object being modified.
+ * @param oldState the state of the object prior to this method call.
+ * @param newState the desired state of the object.
+ */
+ @Override
+ public void stateChanged(final ConfiguredObject object, final State oldState, final State newState)
+ {
+ // no-op
+ }
+
+ /**
+ * ConfigurationChangeListener method called when an attribute is set (ignored here).
+ * @param object the object being modified.
+ * @param attributeName the name of the object attribute that we want to change.
+ * @param oldAttributeValue the value of the attribute prior to this method call.
+ * @param newAttributeValue the desired value of the attribute.
+ */
+ @Override
+ public void attributeSet(ConfiguredObject object, String attributeName,
+ Object oldAttributeValue, Object newAttributeValue)
+ {
+ // no-op
+ }
+
+ /**
+ * ConfigurationChangeListener method called when a child ConfiguredObject is added.
+ * <p>
+ * This method checks the type of the child ConfiguredObject that has been added and creates the equivalent
+ * QMF2 Management Object if one doesn't already exist. In most cases it's a one-to-one mapping, but for
+ * Binding for example the Binding child is added to both Queue and Exchange so we only create the Binding
+ * QMF2 Management Object once and add the queueRef and exchangeRef reference properties referencing the Queue
+ * and Exchange parent Objects respectively.
+ * <p>
+ * This method is also responsible for raising the appropriate QMF2 Events when Management Objects are created.
+ * @param object the parent object that the child is being added to.
+ * @param child the child object being added.
+ */
+ @Override
+ public void childAdded(final ConfiguredObject object, final ConfiguredObject child)
+ {
+//System.out.println("childAdded() " + child.getClass().getSimpleName() + "." + child.getName());
+
+ QmfAgentData data = null;
+
+ if (child instanceof Broker)
+ {
+ data = new org.apache.qpid.server.qmf2.agentdata.Broker((Broker)child);
+ }
+ else if (child instanceof Connection)
+ {
+ if (!agentConnection && !_objects.containsKey(child))
+ {
+ // If the parent object is the default vhost set it to null so that the Connection ignores it.
+ VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost)object;
+ data = new org.apache.qpid.server.qmf2.agentdata.Connection(vhost, (Connection)child);
+ _objects.put(child, data);
+
+ // Raise a Client Connect Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Connection)data).createClientConnectEvent());
+ }
+ agentConnection = false; // Only ignore the first Connection, which is the one from the Agent.
+ }
+ else if (child instanceof Session)
+ { // TODO
+
+ }
+ else if (child instanceof Exchange)
+ {
+ if (!_objects.containsKey(child))
+ {
+ // If the parent object is the default vhost set it to null so that the Connection ignores it.
+ VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost)object;
+ data = new org.apache.qpid.server.qmf2.agentdata.Exchange(vhost, (Exchange)child);
+ _objects.put(child, data);
+
+ // Raise an Exchange Declare Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Exchange)data).createExchangeDeclareEvent());
+
+ }
+ }
+ else if (child instanceof Queue)
+ {
+ if (!_objects.containsKey(child))
+ {
+ // If the parent object is the default vhost set it to null so that the Connection ignores it.
+ VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost)object;
+ data = new org.apache.qpid.server.qmf2.agentdata.Queue(vhost, (Queue)child);
+ _objects.put(child, data);
+
+ // Raise a Queue Declare Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Queue)data).createQueueDeclareEvent());
+ }
+ }
+ else if (child instanceof Binding)
+ {
+ // Bindings are a little more complex because in QMF bindings contain exchangeRef and queueRef properties
+ // whereas with the Java Broker model Binding is a child of Queue and Exchange. To cope with this we
+ // first try to create or retrieve the QMF Binding Object then add either the Queue or Exchange reference
+ // depending on whether Queue or Exchange was the parent of this addChild() call.
+ if (!_objects.containsKey(child))
+ {
+ data = new org.apache.qpid.server.qmf2.agentdata.Binding((Binding)child);
+ _objects.put(child, data);
+
+ String eName = child.getAttribute("exchange").toString();
+ if (!eName.equals("<<default>>")) // Don't send Event for Binding to default direct.
+ {
+ // Raise a Bind Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Binding)data).createBindEvent());
+ }
+ }
+
+ org.apache.qpid.server.qmf2.agentdata.Binding binding =
+ (org.apache.qpid.server.qmf2.agentdata.Binding)_objects.get(child);
+
+ QmfAgentData ref = _objects.get(object);
+ if (ref != null)
+ {
+ if (object instanceof Queue)
+ {
+ binding.setQueueRef(ref.getObjectId());
+ }
+ else if (object instanceof Exchange)
+ {
+ binding.setExchangeRef(ref.getObjectId());
+ }
+ }
+ }
+ else if (child instanceof Consumer) // AKA Subscription
+ {
+ // Subscriptions are a little more complex because in QMF Subscriptions contain sessionRef and queueRef
+ // properties whereas with the Java Broker model Consumer is a child of Queue and Session. To cope with
+ // this we first try to create or retrieve the QMF Subscription Object then add either the Queue or
+ // Session reference depending on whether Queue or Session was the parent of this addChild() call.
+ if (!_objects.containsKey(child))
+ {
+ data = new org.apache.qpid.server.qmf2.agentdata.Subscription((Consumer)child);
+ _objects.put(child, data);
+ }
+
+ org.apache.qpid.server.qmf2.agentdata.Subscription subscription =
+ (org.apache.qpid.server.qmf2.agentdata.Subscription)_objects.get(child);
+
+ QmfAgentData ref = _objects.get(object);
+ if (ref != null)
+ {
+ if (object instanceof Queue)
+ {
+ subscription.setQueueRef(ref.getObjectId(), (Queue)object);
+ // Raise a Subscribe Event - N.B. Need to do it *after* we've set the queueRef.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Subscription)data).createSubscribeEvent());
+ }
+ else if (object instanceof Session) // Won't get called in Qpid 0.20.
+ { // TODO the association between Session and Subscription isn't implemented in the 0.20 Java Broker.
+ //System.out.println("subscription.setSessionRef");
+ subscription.setSessionRef(ref.getObjectId());
+ }
+ }
+ }
+
+
+ try
+ {
+ // If we've created new QmfAgentData we register it with the Agent.
+ if (data != null)
+ {
+ _agent.addObject(data);
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ _log.info("QmfException {} caught in QmfManagementAgent.addObject()", qmfe.getMessage());
+ }
+
+ child.addChangeListener(this);
+ }
+
+
+ /**
+ * ConfigurationChangeListener method called when a child ConfiguredObject is removed.
+ * <p>
+ * This method checks the type of the child ConfiguredObject that has been removed and raises the appropriate
+ * QMF2 Events, it then destroys the QMF2 Management Object and removes the mapping between child and the QMF Object.
+ *
+ * @param object the parent object that the child is being removed from.
+ * @param child the child object being removed.
+ */
+ @Override
+ public void childRemoved(final ConfiguredObject object, final ConfiguredObject child)
+ {
+//System.out.println("childRemoved: " + child.getClass().getSimpleName() + "." + child.getName());
+
+ child.removeChangeListener(this);
+
+ // Look up the associated QmfAgentData and mark it for deletion by the Agent.
+ QmfAgentData data = _objects.get(child);
+ if (data != null)
+ {
+ if (child instanceof Connection)
+ {
+ // Raise a Client Disconnect Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Connection)data).createClientDisconnectEvent());
+ }
+ else if (child instanceof Session)
+ { // TODO
+
+ }
+ else if (child instanceof Exchange)
+ {
+ // Raise an Exchange Delete Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Exchange)data).createExchangeDeleteEvent());
+ }
+ else if (child instanceof Queue)
+ {
+ // Raise a Queue Delete Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Queue)data).createQueueDeleteEvent());
+ }
+ else if (child instanceof Binding)
+ {
+ String eName = child.getAttribute("exchange").toString();
+ if (!eName.equals("<<default>>")) // Don't send Event for Unbinding from default direct.
+ {
+ // Raise an Unbind Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Binding)data).createUnbindEvent());
+ }
+ }
+ else if (child instanceof Consumer)
+ {
+ // Raise an Unsubscribe Event.
+ _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Subscription)data).createUnsubscribeEvent());
+ }
+
+ data.destroy();
+ }
+
+ // Remove the mapping from the internal ConfiguredObject->QmfAgentData Map.
+ _objects.remove(child);
+ }
+
+ // ******************************* QmfEventListener implementation method *******************************
+
+ /**
+ * Callback method triggered when the underlying QMF2 Agent has WorkItems available for processing.
+ * The purpose of this method is mainly to handle the METHOD_CALL WorkItem and demultiplex & delegate
+ * to the invokeMethod() call on the relevant concrete QmfAgentData Object.
+ * @param wi the WorkItem that has been passed by the QMF2 Agent to be processed here (mainly METHOD_CALL).
+ */
+ @Override
+ public void onEvent(final WorkItem wi)
+ {
+ if (wi.getType() == METHOD_CALL)
+ {
+ MethodCallWorkItem item = (MethodCallWorkItem)wi;
+ MethodCallParams methodCallParams = item.getMethodCallParams();
+
+ String methodName = methodCallParams.getName();
+ ObjectId objectId = methodCallParams.getObjectId();
+
+ // Look up QmfAgentData by ObjectId from the Agent's internal Object store.
+ QmfAgentData object = _agent.getObject(objectId);
+ if (object == null)
+ {
+ _agent.raiseException(item.getHandle(), "No object found with ID=" + objectId);
+ }
+ else
+ {
+ // If we've found a valid QmfAgentData check it's a Broker or Queue and if so call the generic
+ // invokeMethod on these objects, if not send an Exception as we don't support methods on
+ // other classes yet.
+ if (object instanceof org.apache.qpid.server.qmf2.agentdata.Broker)
+ {
+ org.apache.qpid.server.qmf2.agentdata.Broker broker =
+ (org.apache.qpid.server.qmf2.agentdata.Broker) object;
+ broker.invokeMethod(_agent, item.getHandle(), methodName, methodCallParams.getArgs());
+ }
+ else if (object instanceof org.apache.qpid.server.qmf2.agentdata.Queue)
+ {
+ org.apache.qpid.server.qmf2.agentdata.Queue queue =
+ (org.apache.qpid.server.qmf2.agentdata.Queue) object;
+ queue.invokeMethod(_agent, item.getHandle(), methodName, methodCallParams.getArgs());
+ }
+ else
+ {
+ _agent.raiseException(item.getHandle(), "Unknown Method " + methodName + " on " +
+ object.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementFactory.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementFactory.java
new file mode 100644
index 0000000000..de6376a2d9
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementFactory.java
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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.server.qmf2;
+
+// Misc Imports
+import java.util.Map;
+import java.util.UUID;
+
+// Java Broker Management Imports
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
+
+/**
+ * This class is an implementation of org.apache.qpid.server.plugin.PluginFactory which is the interface
+ * used by the Qpid Java Broker to create Management Plugins.
+ * <p>
+ * The factory method is createInstance() which returns a concrete instance of org.apache.qpid.server.model.Plugin
+ * in this case the concrete instance is QmfManagementPlugin.
+ * <p>
+ * The Java broker uses org.apache.qpid.server.plugin.QpidServiceLoader, which wraps java.util.ServiceLoader to
+ * load Plugins. This has a prerequisite of having a services file specified in the META-INF see
+ * <a href=http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html>ServiceLoader</a> e.g.
+ * <pre>
+ * META-INF/services/org.apache.qpid.server.plugin.PluginFactory
+ * </pre>
+ * This is best done by using the ServiceProvider block in the jar ant task e.g.
+ * <pre>
+ * &lt;jar destfile="build/lib/qpid-broker-plugins-management-qmf2.jar"
+ * basedir="build/scratch/qpid-broker-plugins-management-qmf2"&gt;
+ *
+ * &lt;service type="org.apache.qpid.server.plugin.PluginFactory"
+ * provider="org.apache.qpid.server.qmf2.QmfManagementFactory"/&gt;
+ * &lt;/jar&gt;
+ * </pre>
+ * @author Fraser Adams
+ */
+public class QmfManagementFactory implements PluginFactory
+{
+ /**
+ * This factory method creates an instance of QmfManagementPlugin called via the QpidServiceLoader.
+ * @param id the UUID of the Plugin.
+ * @param attributes a Map containing configuration information for the Plugin.
+ * @param broker the root Broker Management Object from which the other Management Objects may be obtained.
+ * @return the QmfManagementPlugin instance which creates a QMF2 Agent able to interrogate the broker Management
+ * Objects and return their properties as QmfData.
+ */
+ @Override
+ public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker)
+ {
+ if (QmfManagementPlugin.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE)))
+ {
+ return new QmfManagementPlugin(id, broker, attributes);
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementPlugin.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementPlugin.java
new file mode 100644
index 0000000000..f17930d77a
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/QmfManagementPlugin.java
@@ -0,0 +1,300 @@
+/*
+ *
+ * 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.server.qmf2;
+
+// Misc Imports
+import java.lang.reflect.Type;
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Java Broker Management Imports
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AbstractPluginAdapter;
+
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.util.MapValueConverter;
+
+/**
+ * This class is a Qpid Java Broker Plugin which follows the Plugin API added in Qpid 0.22 it implements
+ * org.apache.qpid.server.model.Plugin and extends org.apache.qpid.server.model.adapter.AbstractPluginAdapter.
+ * <p>
+ * This Plugin provides access to the Java broker Management Objects via QMF2 thus allowing the Java broker to
+ * be managed and monitored in the same way as the C++ broker.
+ * <p>
+ * The intention is for the Java broker QmfManagementPlugin to conform to the same Management Schema as the C++
+ * broker (e.g. as specified in <qpid>/specs/management-schema.xml) in order to provide maximum cohesion between
+ * the to broker implementations, however that's not entirely possible given differences between the underlying
+ * Management models. The ultimate aim is to align the Management models of the two Qpid brokers and migrate
+ * to the AMQP 1.0 Management architecture when it becomes available.
+ * <p>
+ * This Plugin attempts to map properties from the Java org.apache.qpid.server.model.* classes to equivalent
+ * properties and statistics in the C++ broker's Management Schema rather than expose them "natively", this is
+ * in order to try and maximise alignment between the two implementations and to try to allow the Java broker
+ * to be managed by the Command Line tools used with the C++ broker such as qpid-config etc. it's also to
+ * enable the Java broker to be accessed via the QMF2 REST API and GUI.
+ * <p>
+ * This class only bootstraps the ManagementPlugin, the actual business logic is run from QmfManagementAgent.
+ * It's worth also mentioning that this Plugin actually establishes an AMQP Connection to the Broker via JMS.
+ * As it's a Broker Plugin it could conceivably use the low level Broker internal transport, this would probably
+ * be a little more efficient, but OTOH by using the JMS based approach I can use the QMF2 Agent code
+ * directly and implementing a complete QMF2 Agent for the Java Broker becomes "fairly simple" only requiring
+ * mappings between the org.apache.qpid.server.model.* classes and their QmfAgentData equivalents.
+ * <p>
+ * This Plugin requires config to be set, if this is not done the Plugin will not bootstrap. Config may be
+ * set in $QPID_WORK/config.json as part of the "plugins" config e.g.
+ * <pre>
+ * "plugins" : [ {
+ * "id" : "26887211-842c-3c4a-ab09-b1a1f64de369",
+ * "name" : "qmf2Management",
+ * "pluginType" : "MANAGEMENT-QMF2",
+ * "connectionURL" : "amqp://guest:guest@/?brokerlist='tcp://0.0.0.0:5672'"
+ * }]
+ * </pre>
+ * @author Fraser Adams
+ */
+public class QmfManagementPlugin extends AbstractPluginAdapter
+{
+ private static final Logger _log = LoggerFactory.getLogger(QmfManagementPlugin.class);
+
+ private static final String OPERATIONAL_LOGGING_NAME = "QMF2";
+
+ /************* Static initialiser used to implement org.apache.qpid.server.model.Plugin *************/
+
+ public static final String PLUGIN_TYPE = "MANAGEMENT-QMF2";
+
+ // attributes
+ public static final String NAME = "name";
+ public static final String CONNECTION_URL = "connectionURL";
+
+ // default values
+ public static final String DEFAULT_NAME = "qmf2Management";
+ public static final String DEFAULT_CONNECTION_URL = "amqp://guest:guest@/?brokerlist='tcp://0.0.0.0:5672'";
+
+ @SuppressWarnings("serial")
+ private static final Collection<String> AVAILABLE_ATTRIBUTES = Collections.unmodifiableCollection(
+ new HashSet<String>(Plugin.AVAILABLE_ATTRIBUTES){{
+ add(NAME);
+ add(CONNECTION_URL);
+ add(PluginFactory.PLUGIN_TYPE);
+ }});
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Object> DEFAULTS = new HashMap<String, Object>(){{
+ put(NAME, DEFAULT_NAME);
+ put(CONNECTION_URL, DEFAULT_CONNECTION_URL);
+ put(PluginFactory.PLUGIN_TYPE, PLUGIN_TYPE);
+ }};
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Type> ATTRIBUTE_TYPES = new HashMap<String, Type>(){{
+ put(NAME, String.class);
+ put(CONNECTION_URL, String.class);
+ put(PluginFactory.PLUGIN_TYPE, String.class);
+ }};
+
+ /************************************ End of Static initialiser *************************************/
+
+ private final Broker _broker; // Passed in by Plugin bootstrapping.
+ private final String _defaultVirtualHost; // Pulled from the broker attributes.
+ private final String _connectionURL; // Pulled from the Plugin config.
+ private QmfManagementAgent _agent;
+
+ /**
+ * Constructor, called at broker startup by QmfManagementFactory.createInstance().
+ * @param id the UUID of the Plugin.
+ * @param attributes a Map containing configuration information for the Plugin.
+ * @param broker the root Broker Management Object from which the other Management Objects may be obtained.
+ */
+ public QmfManagementPlugin(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), broker.getTaskExecutor());
+ addParent(Broker.class, broker);
+ _broker = broker;
+ _defaultVirtualHost = (String)broker.getAttribute("defaultVirtualHost");
+ _connectionURL = (String)getAttribute("connectionURL");
+ }
+
+ /**
+ * Set the state of the Plugin, I believe that this is called from the BrokerAdapter object when it
+ * has its own state set to State.ACTIVE or State.STOPPED.
+ * When State.ACTIVE is set this calls the start() method to startup the Plugin, when State.STOPPED
+ * is set this calls the stop() method to shutdown the Plugin.
+ * @param currentState the current state of the Plugin (ignored).
+ * @param desiredState the desired state of the Plugin (either State.ACTIVE or State.STOPPED).
+ * @return true if a valid state has been set, otherwise false.
+ */
+ @Override // From org.apache.qpid.server.model.adapter.AbstractAdapter
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ start();
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ stop();
+ return true;
+ }
+ else
+ {
+ _log.info("QmfManagementPlugin.setState() received invalid desiredState {}", desiredState);
+ return false;
+ }
+ }
+
+ /**
+ * Start the Plugin. Note that we bind the QMF Connection the the default Virtual Host, this is important
+ * in order to allow C++ or Python QMF Consoles to control the Java Broker, as they know nothing of Virtual
+ * Hosts and their Connection URL formats don't have a mechanism to specify Virtual Hosts.
+ * <p>
+ * Note too that it may be necessary to create the "qmf.default.direct" and "qmf.default.topic" exchanges
+ * as these don't exist by default on the Java Broker, however we have to check if they already exist
+ * as attempting to add an Exchange that already exists will cause IllegalArgumentException.
+ */
+ private void start()
+ {
+ // Log "QMF2 Management Startup" message.
+ CurrentActor.get().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
+
+ // Wrap main startup logic in a try/catch block catching Exception. The idea is that if anything goes
+ // wrong with QmfManagementPlugin startup it shouldn't fatally prevent the Broker from starting, though
+ // clearly QMF2 management will not be available.
+ try
+ {
+ // Iterate through the Virtual Hosts looking for the default Virtual Host. When we find the default
+ // we create the QMF exchanges then construct the QmfManagementAgent passing it the ConnectionURL.
+ boolean foundDefaultVirtualHost = false;
+ for (VirtualHost vhost : _broker.getVirtualHosts())
+ {
+ if (vhost.getName().equals(_defaultVirtualHost))
+ {
+ foundDefaultVirtualHost = true;
+
+ // Check if "qmf.default.direct" or "qmf.default.topic" already exist. It is important to
+ // check as attempting to add an Exchange that already exists will cause IllegalArgumentException.
+ boolean needDefaultDirect = true;
+ boolean needDefaultTopic = true;
+ for (Exchange exchange : vhost.getExchanges())
+ {
+ if (exchange.getName().equals("qmf.default.direct"))
+ {
+ needDefaultDirect = false;
+ }
+ else if (exchange.getName().equals("qmf.default.topic"))
+ {
+ needDefaultTopic = false;
+ }
+ }
+
+ // Create the QMF2 exchanges if necessary.
+ Map<String, Object> attributes = Collections.emptyMap();
+ if (needDefaultDirect)
+ {
+ vhost.createExchange("qmf.default.direct", State.ACTIVE, true,
+ LifetimePolicy.PERMANENT, 0l, "direct", attributes);
+ }
+
+ if (needDefaultTopic)
+ {
+ vhost.createExchange("qmf.default.topic", State.ACTIVE, true,
+ LifetimePolicy.PERMANENT, 0l, "topic", attributes);
+ }
+
+ // Now create the *real* Agent which maps Broker Management Objects to QmdAgentData Objects.
+ _agent = new QmfManagementAgent(_connectionURL, _broker);
+ }
+ }
+
+ // If we can't find a defaultVirtualHost we log that fact, the Plugin can't start in this case.
+ // Question. If defaultVirtualHost isn't configured or it doesn't match the name of one of the actual
+ // Virtual Hosts should we make the first one we find the de facto default for this Plugin??
+ if (!foundDefaultVirtualHost)
+ {
+ _log.info("QmfManagementPlugin.start() could not find defaultVirtualHost");
+ }
+ else if (_agent.isConnected())
+ {
+ // Log QMF2 Management Ready message.
+ CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
+ }
+ }
+ catch (Exception e) // Catch and log any Exception so we avoid Plugin failures stopping Broker startup.
+ {
+ _log.info("Exception {} caught in QmfManagementPlugin.start()", e.getMessage());
+ }
+ }
+
+ /**
+ * Stop the Plugin, closing the QMF Connection and logging "QMF2 Management Stopped".
+ */
+ private void stop()
+ {
+ // When the Plugin state gets set to STOPPED we close the QMF Connection.
+ if (_agent != null)
+ {
+ _agent.close();
+ }
+
+ // Log "QMF2 Management Stopped" message (may not get displayed).
+ CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
+ }
+
+ /**
+ * Get the name of this Plugin.
+ * @return the Plugin name (default is "qmf2Management").
+ */
+ @Override // From org.apache.qpid.server.model.ConfiguredObject
+ public String getName()
+ {
+ return (String)getAttribute(NAME);
+ }
+
+ /**
+ * Accessor to retrieve the names of the available attributes. It is important to provide this overridden
+ * method because the Constructor uses this information when populating the underlying AbstractPlugin
+ * information. If we don't provide this override method getAttribute(name) will return the default values.
+ * @return the names of the available Plugin config attributes as a Collection.
+ */
+ @Override // From org.apache.qpid.server.model.adapter.AbstractPluginAdapter
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Binding.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Binding.java
new file mode 100644
index 0000000000..23d5ce5663
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Binding.java
@@ -0,0 +1,203 @@
+/*
+ *
+ * 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.server.qmf2.agentdata;
+
+// Misc Imports
+import java.util.Map;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+//import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+//import org.apache.qpid.qmf2.common.SchemaProperty;
+
+import org.apache.qpid.server.model.Statistics;
+
+/**
+ * This class provides a concrete implementation of QmfAgentData for the Binding Management Object.
+ * In general it's possible to use QmfAgentData without sub-classing as it's really a "bean" style class
+ * that retains its properties in a Map, but in the case of the Java Broker Management Agent it's useful
+ * to sub-class as we need to map between the properties/statistics as specified in the Java Broker
+ * management model and those specified in qpid/spec/management-schema.xml which is what the C++ broker
+ * uses. This class retains a reference to its peer org.apache.qpid.server.model.Binding and does the
+ * necessary mapping when its mapEncode() method is called (which is used to serialise the QmfAgentData).
+ *
+ * @author Fraser Adams
+ */
+public class Binding extends QmfAgentData
+{
+ private static final Logger _log = LoggerFactory.getLogger(Binding.class);
+
+ /**
+ * This static initialiser block initialises the QMF2 Schema information needed by the Agent to find
+ * QmfAgentData and QmfEvent Objects of a given type.
+ */
+ private static final SchemaObjectClass _schema;
+ private static final SchemaEventClass _bindSchema;
+ private static final SchemaEventClass _unbindSchema;
+
+ /**
+ * Returns the schema for the Binding class.
+ * @return the SchemaObjectClass for the Binding class.
+ */
+ public static SchemaObjectClass getSchema()
+ {
+ return _schema;
+ }
+
+ /**
+ * Returns the schema for the Bind Event.
+ * @return the SchemaEventClass for the Bind Event.
+ */
+ public static SchemaEventClass getBindSchema()
+ {
+ return _bindSchema;
+ }
+
+ /**
+ * Returns the schema for the Unbind Event.
+ * @return the SchemaEventClass for the Unbind Event.
+ */
+ public static SchemaEventClass getUnbindSchema()
+ {
+ return _unbindSchema;
+ }
+
+ static
+ {
+ // Declare the schema for the QMF2 broker class.
+ _schema = new SchemaObjectClass("org.apache.qpid.broker", "binding");
+
+ // TODO
+ //_schema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+
+ // Declare the schema for the QMF2 bind Event class.
+ _bindSchema = new SchemaEventClass("org.apache.qpid.broker", "bind");
+
+ // Declare the schema for the QMF2 unbind Event class.
+ _unbindSchema = new SchemaEventClass("org.apache.qpid.broker", "unbind");
+ }
+ // End of static initialiser.
+
+ private final org.apache.qpid.server.model.Binding _binding;
+
+ /**
+ * Constructor.
+ * @param binding the Binding ConfiguredObject from the broker model.
+ */
+ public Binding(final org.apache.qpid.server.model.Binding binding)
+ {
+ super(getSchema());
+ _binding = binding; // Will eventually be used in mapEncode() to retrieve statistics.
+ setValue("bindingKey", binding.getName());
+
+ Map<String, Object> arguments = binding.getArguments();
+ // binding.getArguments() always returns a Map, but with the C++ broker if there are no arguments
+ // the property isn't populated, so we only add it if the _arguments.size() > 0
+ if (arguments.size() > 0)
+ {
+ setValue("arguments", arguments);
+ }
+
+ // origin not implemented in Qpid 0.20 - not really sure what the origin property means anyway???
+ }
+
+ /**
+ * Set the exchangeRef property.
+ * @param exchangeRef the exchangeRef ObjectId.
+ */
+ public void setExchangeRef(final ObjectId exchangeRef)
+ {
+ setRefValue("exchangeRef", exchangeRef);
+ }
+
+ /**
+ * Set the queueRef property.
+ * @param queueRef the queueRef ObjectId.
+ */
+ public void setQueueRef(final ObjectId queueRef)
+ {
+ setRefValue("queueRef", queueRef);
+ }
+
+ /**
+ * Factory method to create a Bind Event Object with timestamp of now.
+ * @return the newly created Bind Event Object.
+ */
+ public QmfEvent createBindEvent()
+ {
+ QmfEvent bind = new QmfEvent(_bindSchema);
+ bind.setSeverity("info");
+ bind.setValue("args", _binding.getArguments());
+ bind.setValue("exName", _binding.getAttribute("exchange"));
+ bind.setValue("key", _binding.getName());
+ bind.setValue("qName", _binding.getAttribute("queue"));
+ // TODO Not sure of a way to get these for Java Broker Exchange.
+ //bind.setValue("rhost", _connection.getName());
+ //bind.setValue("user", getStringValue("authIdentity"));
+ return bind;
+ }
+
+ /**
+ * Factory method to create an Unbind Event Object with timestamp of now.
+ * @return the newly created Unbind Event Object.
+ */
+ public QmfEvent createUnbindEvent()
+ {
+ QmfEvent unbind = new QmfEvent(_unbindSchema);
+ unbind.setSeverity("info");
+ unbind.setValue("exName", _binding.getAttribute("exchange"));
+ unbind.setValue("key", _binding.getName());
+ unbind.setValue("qName", _binding.getAttribute("queue"));
+ // TODO Not sure of a way to get these for Java Broker Exchange.
+ //unbind.setValue("rhost", _connection.getName());
+ //unbind.setValue("user", getStringValue("authIdentity"));
+ return unbind;
+ }
+
+ /**
+ * This method maps the org.apache.qpid.server.model.Binding to QMF2 broker properties where possible then
+ * serialises into the underlying Map for transmission via AMQP. This method is called by handleQueryRequest()
+ * in the org.apache.qpid.qmf2.agent.Agent class implementing the main QMF2 Agent behaviour.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ // Statistics
+ //Statistics stats = _binding.getStatistics();
+ // not implemented in Qpid 0.20 despite the property actually existing!!
+ //setValue("msgMatched", stats.getStatistic("matchedMessages"));
+
+ //update(); // No statistics have been updated ('cause there aren't any yet...)
+ return super.mapEncode();
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Broker.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Broker.java
new file mode 100644
index 0000000000..fda1b7ad84
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Broker.java
@@ -0,0 +1,678 @@
+/*
+ *
+ * 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.server.qmf2.agentdata;
+
+// Misc Imports
+import java.util.Collections;
+import java.util.Map;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.Agent;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+/*import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfType;*/
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+
+// Java Broker model Imports
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+
+/**
+ * This class provides a concrete implementation of QmfAgentData for the Broker Management Object.
+ * In general it's possible to use QmfAgentData without sub-classing as it's really a "bean" style class
+ * that retains its properties in a Map, but in the case of the Java Broker Management Agent it's useful
+ * to sub-class as we need to map between the properties/statistics as specified in the Java Broker
+ * management model and those specified in qpid/spec/management-schema.xml which is what the C++ broker
+ * uses. This class retains a reference to its peer org.apache.qpid.server.model.Broker and does the
+ * necessary mapping when its mapEncode() method is called (which is used to serialise the QmfAgentData).
+ *
+ * @author Fraser Adams
+ */
+public class Broker extends QmfAgentData
+{
+ private static final Logger _log = LoggerFactory.getLogger(Broker.class);
+
+ /**
+ * This static initialiser block initialises the QMF2 Schema information needed by the Agent to find
+ * QmfAgentData Objects of a given type.
+ */
+ private static final SchemaObjectClass _schema;
+ public static SchemaObjectClass getSchema()
+ {
+ return _schema;
+ }
+
+ static
+ {
+ // Declare the schema for the QMF2 broker class.
+ _schema = new SchemaObjectClass("org.apache.qpid.broker", "broker");
+
+ // TODO
+ //_schema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+ }
+
+ private final org.apache.qpid.server.model.Broker _broker; // Passed in by Plugin bootstrapping.
+ private final String _defaultVirtualHost; // Pulled from the broker attributes.
+
+ /**
+ * This inner class parses the name String that was passed in as a QMF method argument.
+ * There are a few quirks with this name. In the first instance it may be prefixed with Virtual Host information
+ * e.g. [vhost:<vhost-name>/]<queue-name> this is because in order to allow Java Broker QMF to work with things like
+ * qpid-config which are not particularly Virtual Host aware prefixing the names seemed to be the most natural,
+ * if slightly ugly approach. In addition the way bindings are named is of the form:
+ * <exchange-name>/<queue-name>[/<binding-key>] so we need a mechanism to parse the relevant information.
+ * <p>
+ * N.B. the parsing that takes place in this class makes an assumption that there are no valid exchange or queue
+ * names that contain a "/". This is probably a reasonable assumption given the way that a binding name is
+ * constructed, but it's worth recording the restriction here in case such a beast crops up.
+ * <p>
+ * This class also provides accessors that allow the Exchange, Queue and Binding ConfiguredObjects for the
+ * name parsed in the Constructor to be retrieved. This is generally useful because although in QMF the create
+ * and delete methods are invoked on the Broker object in the Java Broker ConfiguredObject model the underlying
+ * methods are distributed across a number of different classes.
+ */
+ private class NameParser
+ {
+ private String _vhostName = _defaultVirtualHost;
+ private VirtualHost _vhost = null;
+ private String _exchangeName = "";
+ private Exchange _exchange = null;
+ private String _queueName = "";
+ private Queue _queue = null;
+ private String _bindingKey = "";
+ private Binding _binding = null;
+
+ /**
+ * NameParser Constructor.
+ * The Constructor actually does the majority of the parsing, the remaining method are largely just accessors.
+ *
+ * @param name the name argument that was retrieved from the QMF method inArgs. This will be the exchange name,
+ * the queue name or the binding name (which is of the form <exchange-name>/<queue-name>[/<binding-key>])
+ * exchange and queue names may be prefixed by a Virtual Host name e.g. [vhost:<vhost-name>/]<queue-name>
+ * @param type the type argument that was retrieved from the QMF method inArgs. Valid types are "exchange,
+ * "queue" or "binding".
+ */
+ public NameParser(final String name, final String type)
+ {
+ boolean malformedVHostName = false;
+ String[] splitName = name.split("/"); // A slash is used as a separator in a couple of scenarios.
+ if (name.startsWith("vhost:"))
+ {
+ if (splitName.length == 1) // If it starts with vhost: the name should also contain at least one "/".
+ {
+ malformedVHostName = true;
+ _vhostName = name;
+ }
+ else
+ {
+ _vhostName = splitName[0];
+ _vhostName = _vhostName.substring(6, _vhostName.length());
+ }
+ }
+
+ // If the vhostName isn't malformed then try to find the actual Virtual Host that it relates to.
+ // If it is malformed the vhost stays set to null, which will cause an exception to be returned later.
+ if (!malformedVHostName)
+ {
+ for (VirtualHost vhost : _broker.getVirtualHosts())
+ {
+ if (vhost.getName().equals(_vhostName))
+ {
+ _vhost = vhost;
+ break;
+ }
+ }
+ }
+
+ // Populate the exchange, queue and binding names. We only populate the names in the constructor
+ // when we actually want to find the Object associated with the name we do it "on demand" in the
+ // relevant accessor and cache the result.
+ if (type.equals("exchange"))
+ {
+ _exchangeName = splitName[splitName.length - 1];
+ }
+ else if (type.equals("queue"))
+ {
+ _queueName = splitName[splitName.length - 1];
+ }
+ else if (type.equals("binding"))
+ { // TODO is there a way to make this parse less nasty and a bit more elegant....
+ int i = 0;
+ String vhost1Name = _defaultVirtualHost; // The exchange and queue vhostName need to be the same.
+ if (splitName[i].startsWith("vhost:")) // Does the exchange name specify a vhost?
+ {
+ vhost1Name = splitName[i];
+ i++;
+ }
+
+ if (i < splitName.length) // Extract the exchange name sans vhost part.
+ {
+ _exchangeName = splitName[i];
+ i++;
+ }
+
+ String vhost2Name = _defaultVirtualHost;
+ if (i < splitName.length && splitName[i].startsWith("vhost:")) // Does the queue name specify a vhost?
+ {
+ vhost2Name = splitName[i];
+ i++;
+ }
+
+ // If the exchange and queue vhost names differ set _vhost and _vhostName to null which causes
+ // an exception that says "VirtualHost names for exchange and queue must match.".
+ if (!vhost2Name.equals(vhost1Name))
+ {
+ _vhost = null;
+ _vhostName = null;
+ }
+
+ if (i < splitName.length) // Extract the queue name sans vhost part.
+ {
+ _queueName = splitName[i];
+ i++;
+ }
+
+ if (i < splitName.length) // Extract the binding key if present (it's optional).
+ {
+ _bindingKey = splitName[i];
+ i++;
+ }
+ } // End of binding name parse.
+ }
+
+ // NameParser accessors.
+
+ /**
+ * Retrieves the name of the Virtual Host that was parsed from the name supplied in the Constructor.
+ * @return the parsed Virtual Host name (may be an empty String).
+ */
+ public String getVirtualHostName()
+ {
+ return _vhostName;
+ }
+
+ /**
+ * Retrieves the Virtual Host with the name that was parsed from the name supplied in the Constructor.
+ * @return the Virtual Host with the name that was parsed from the name supplied in the Constructor (may be null).
+ */
+ public VirtualHost getVirtualHost()
+ {
+ return _vhost;
+ }
+
+ /**
+ * Retrieves the name of the Exchange that was parsed from the name supplied in the Constructor.
+ * @return the parsed Exchange name (may be an empty String).
+ */
+ public String getExchangeName()
+ {
+ return _exchangeName;
+ }
+
+ /**
+ * Retrieves the Exchange with the name that was parsed from the name supplied in the Constructor.
+ * @return the Exchange with the name that was parsed from the name supplied in the Constructor (may be null).
+ */
+ public Exchange getExchange()
+ {
+ // If we've not previously cached the _exchange and the previously parsed Virtual Host isn't null we do a
+ // look up for the actual Exchange with the name _exchangeName and cache it.
+ if (_exchange == null && _vhost != null)
+ {
+ for (Exchange exchange : _vhost.getExchanges())
+ {
+ if (exchange.getName().equals(_exchangeName))
+ {
+ _exchange = exchange;
+ break;
+ }
+ }
+ }
+
+ return _exchange;
+ }
+
+ /**
+ * Retrieves the name of the Queue that was parsed from the name supplied in the Constructor.
+ * @return the parsed Queue name (may be an empty String).
+ */
+ public String getQueueName()
+ {
+ return _queueName;
+ }
+
+ /**
+ * Retrieves the Queue with the name that was parsed from the name supplied in the Constructor.
+ * @return the Queue with the name that was parsed from the name supplied in the Constructor (may be null).
+ */
+ public Queue getQueue()
+ {
+ // If we've not previously cached the _queue and the previously parsed Virtual Host isn't null we do a
+ // look up for the actual Queue with the name _queueName and cache it.
+ if (_queue == null && _vhost != null)
+ {
+ for (Queue queue : _vhost.getQueues())
+ {
+ if (queue.getName().equals(_queueName))
+ {
+ _queue = queue;
+ break;
+ }
+ }
+ }
+
+ return _queue;
+ }
+
+ /**
+ * Retrieves the name of the Binding that was parsed from the name supplied in the Constructor.
+ * @return the parsed Binding name (may be an empty String).
+ */
+ public String getBindingKey()
+ {
+ return _bindingKey;
+ }
+
+ /**
+ * Retrieves the Binding with the name that was parsed from the name supplied in the Constructor.
+ * @return the Binding with the name that was parsed from the name supplied in the Constructor (may be null).
+ */
+ public Binding getBinding()
+ {
+ // In order to retrieve a Binding it's first necessary to get the Exchange (or Queue) ConfiguredObject.
+ _exchange = getExchange(); // Need to get it via the accessor as it's initialised by lazy evaluation.
+
+ // If we've not previously cached the _binding and the previously retrieved Exchange isn't null we do a
+ // look up for the actual Binding with the name _bindingKey and cache it.
+ if (_binding == null && _exchange != null)
+ {
+ for (Binding binding : _exchange.getBindings())
+ {
+ if (binding.getName().equals(_bindingKey))
+ {
+ _binding = binding;
+ break;
+ }
+ }
+ }
+
+ return _binding;
+ }
+ } // End of class NameParser
+
+ /**
+ * Broker Constructor.
+ * @param broker the root Broker Management Object from which the other Management Objects may be obtained.
+ */
+ public Broker(final org.apache.qpid.server.model.Broker broker)
+ {
+ super(getSchema());
+ _broker = broker;
+ _defaultVirtualHost = (String)broker.getAttribute("defaultVirtualHost");
+ int amqpPort = 5672; // Default AMQP Port.
+
+ // Search through the available Ports on this Broker looking for the AMQP Port. When we find the
+ // AMQP Port we record that in amqpPort;
+ for (Port port : _broker.getPorts())
+ {
+ boolean isAMQP = false;
+ for (Protocol protocol : port.getProtocols())
+ {
+ isAMQP = protocol.isAMQP();
+ if (isAMQP)
+ {
+ break;
+ }
+ }
+
+ if (isAMQP)
+ {
+ amqpPort = port.getPort();
+ break;
+ }
+ }
+
+ String port = "" + amqpPort;
+
+ // systemRef is ignored in this implementation.
+ // stagingThreshold is ignored in this implementation (it's deprecated anyway I believe).
+
+ // Use this name to be fairly consistent with C++ broker which uses "amqp-broker".
+ // N.B. although it's useful to be able to distinguish between C++ and Java brokers note that the
+ // _object_name in the ObjectId that we set below uses actually uses "amqp-broker" vice "amqp-java-broker",
+ // this is because qpid-config uses a "hardcoded" ObjectId to invoke methods so we need to use the same name.
+ setValue("name", "amqp-java-broker");
+ setValue("port", port);
+
+ // workerThreads doesn't *appear* to be configurable in the Java Broker, looks like there's no pool and the
+ // Threads just grow with the number of Connections?
+ setValue("workerThreads", 0);
+
+ // maxConns doesn't *appear* to be configurable in the Java Broker.
+ setValue("maxConns", 0);
+
+ // The Java Broker ServerSocket seems to be created in org.apache.qpid.transport.network.io.IoNetworkTransport
+ // In AcceptingThread. The does't appear to use any configuration for ServerSocket, which suggests that the
+ // backlog is the default value which is assumed to be 10.
+ setValue("connBacklog", 10);
+
+ // "Technically" this isn't quite the same as for the C++ broker, which pushes management data to a particular
+ // topic - the subscription "qmf.default.topic/agent.ind.#" grabs that plus heartbeats for the C++ broker.
+ // This Agent allows the use of the QMF2 Query Subscriptions (which the C++ broker does not!! - the Console
+ // class fakes this client side for the C++ broker. TODO make sure that the Console does not fake for Java broker.
+ setValue("mgmtPublish", true);
+ setValue("mgmtPubInterval", 10);
+
+ setValue("version", org.apache.qpid.common.QpidProperties.getReleaseVersion());
+ setValue("dataDir", System.getProperty("QPID_WORK"));
+
+ // ObjectId needs to be set here in Broker because the QMF2 version of qpid-config uses a hardcoded
+ // _object_name of "org.apache.qpid.broker:broker:amqp-broker" in the _object_id that it sets.
+ // It *shouldn't* do this and should really use the _object_id of the broker object returned by
+ // getObjects("broker"), but it does. The following line causes the Agent to use the explicit
+ // ObjectId below rather than constructing its own, which fixes the qpid-config issue.
+ // Note we use "amqp-broker" in the ObjectId to be compatible with qpid-config but we set the actual
+ // name to "amqp-java-broker" as it's useful to be able to distinguish between C++ and Java Brokers.
+ setObjectId(new ObjectId("", "org.apache.qpid.broker:broker:amqp-broker", 0));
+ }
+
+ /**
+ * This helper method checks the supplied properties Map for the "alternate-exchange" property, if it is present
+ * the property is removed from the map and the alternate exchange is parsed to recover the Virtual Host name
+ * and the actual alternate exchange name. If the alternate exchange Virtual Host name is not the same as the
+ * supplied vhostName this method returns "invalid" otherwise it returns the alternate exchange name or null.
+ *
+ * @param vhostName the Virtual Host name that we want to compare the alternate exchange's Virtual Host name with.
+ * @param properties a Map of properties that might contain "alternate-exchange".
+ * @return the alternate exchange name if present, null if not present or "invalid" if the Virtual Host name that
+ * was parsed from the alternate exchange doesn't match the name supplied in the vhostName parameter.
+ */
+ private String parseAlternateExchange(String vhostName, Map<String, Object> properties)
+ {
+ String alternateExchange = null;
+ Object property = properties.get("alternate-exchange");
+ if (property != null && property instanceof String) // Alternate exchange has been specified.
+ {
+ alternateExchange = property.toString();
+ properties.remove("alternate-exchange");
+
+ String altExVhostName = _defaultVirtualHost;
+ String[] splitName = alternateExchange.split("/");
+ if (alternateExchange.startsWith("vhost:"))
+ {
+ altExVhostName = splitName[0];
+ altExVhostName = altExVhostName.substring(6, altExVhostName.length());
+ }
+
+ // If the Virtual Hosts differ raise an exception and return.
+ if (!altExVhostName.equals(vhostName))
+ {
+ return "invalid";
+ }
+ }
+
+ return alternateExchange;
+ }
+
+ /**
+ * This method acts as a single entry point for QMF methods invoked on the Broker Object.
+ *
+ * @param agent the org.apache.qpid.qmf2.agent.Agent instance that we call methodResponse() and raiseException() on.
+ * @param handle the reply handle used by methodResponse() and raiseException().
+ * @param methodName the name of the QMF method being invoked.
+ * @param inArgs a Map of input arguments wrapped in a QmfData Object.
+ */
+ public void invokeMethod(Agent agent, Handle handle, String methodName, QmfData inArgs)
+ {
+ if (methodName.equals("create") || methodName.equals("delete"))
+ {
+ QmfData outArgs = new QmfData();
+
+ String name = inArgs.getStringValue("name");
+ String type = inArgs.getStringValue("type");
+
+ NameParser nameParser = new NameParser(name, type);
+ String vhostName = nameParser.getVirtualHostName();
+ VirtualHost vhost = nameParser.getVirtualHost();
+
+ if (vhost == null)
+ {
+ if (vhostName == null)
+ {
+ agent.raiseException(handle, "VirtualHost names for exchange and queue must match.");
+ }
+ else
+ {
+ agent.raiseException(handle, "VirtualHost " + vhostName + " not found.");
+ }
+ }
+ else
+ {
+ if (methodName.equals("create")) // method = create
+ {
+ try
+ {
+ //boolean strict = inArgs.getBooleanValue("strict");
+ Map<String, Object> properties = inArgs.getValue("properties");
+
+ boolean durable = false;
+ Object property = properties.get("durable");
+ if (property != null && property instanceof Boolean)
+ {
+ Boolean durableProperty = (Boolean)property;
+ durable = durableProperty.booleanValue();
+ properties.remove("durable");
+ }
+
+ if (type.equals("exchange")) // create exchange.
+ {
+/*
+System.out.println("Create Exchange");
+System.out.println("vhostName = " + vhostName);
+System.out.println("exchange name = " + nameParser.getExchangeName());
+System.out.println("properties = " + properties);
+*/
+ String exchangeType = "";
+ property = properties.get("exchange-type");
+ if (property != null && property instanceof String)
+ {
+ exchangeType = property.toString();
+ properties.remove("exchange-type");
+ }
+
+ String alternateExchange = parseAlternateExchange(vhostName, properties);
+ if (alternateExchange != null && alternateExchange.equals("invalid"))
+ {
+ agent.raiseException(handle, "Alternate Exchange must belong to the same Virtual Host as the Exchange being added.");
+ return;
+ }
+
+ // TODO delete this block when adding an AlternateExchange is implemented.
+ if (alternateExchange != null)
+ {
+ agent.raiseException(handle,
+ "Setting an Alternate Exchange on an Exchange is not yet implemented.");
+ return;
+ }
+
+ // Note that for Qpid 0.20 the "qpid.msg_sequence=1" and "qpid.ive=1" properties are
+ // not suppored, indeed no exchange properties seem to be supported yet.
+ vhost.createExchange(nameParser.getExchangeName(), State.ACTIVE, durable,
+ LifetimePolicy.PERMANENT, 0l, exchangeType, properties);
+ if (alternateExchange != null)
+ {
+ // TODO set Alternate Exchange. There doesn't seem to be a way to do this yet!!!
+ }
+ } // End of create exchange.
+ else if (type.equals("queue")) // create queue.
+ {
+/*
+System.out.println("Create Queue");
+System.out.println("vhostName = " + vhostName);
+System.out.println("queue name = " + nameParser.getQueueName());
+System.out.println("properties = " + properties);
+*/
+
+ // TODO Try to map from the QMF create queue properties to the closest equivalents on
+ // the Java Broker. Unfortunately there are a *lot* of frustrating little differences.
+
+
+ String alternateExchange = parseAlternateExchange(vhostName, properties);
+ if (alternateExchange != null && alternateExchange.equals("invalid"))
+ {
+ agent.raiseException(handle, "Alternate Exchange must belong to the same Virtual Host as the Queue being added.");
+ return;
+ }
+
+ // I don't *think* that it make sense to allow setting exclusive or autoDelete to
+ // a queue created from config.
+ Queue queue = vhost.createQueue(nameParser.getQueueName(), State.ACTIVE, durable, false,
+ LifetimePolicy.PERMANENT, 0l, properties);
+
+ // Set the queue's alternateExchange, which is just a little bit involved......
+ // The queue.setAttribute() method needs an org.apache.qpid.server.model.Exchange instance
+ // not just a name, so we look up org.apache.qpid.server.qmf2.agentdata.Exchange by ID
+ // and get its associated org.apache.qpid.server.model.Exchange. We can do a look up by ID
+ // because we needed to use ObjectIds that were based on names in order to allow qpid-config
+ // to work, so we may as well make use of this convenience here too.
+ if (alternateExchange != null)
+ {
+ ObjectId objectId =
+ new ObjectId("", "org.apache.qpid.broker:exchange:" + alternateExchange, 0);
+
+ // Look up Exchange QmfAgentData by ObjectId from the Agent's internal Object store.
+ QmfAgentData object = agent.getObject(objectId);
+ if (object != null)
+ {
+ org.apache.qpid.server.qmf2.agentdata.Exchange ex =
+ (org.apache.qpid.server.qmf2.agentdata.Exchange)object;
+
+ Exchange altEx = ex.getExchange();
+ queue.setAttribute("alternateExchange", null, altEx);
+ }
+ }
+ }
+ else if (type.equals("binding")) // create binding.
+ {
+ Exchange exchange = nameParser.getExchange();
+ if (exchange == null)
+ {
+ agent.raiseException(handle, "Cannot create binding on Exchange " +
+ nameParser.getExchangeName());
+ return;
+ }
+ else
+ {
+ Map<String, Object> attributes = Collections.emptyMap();
+ exchange.createBinding(nameParser.getBindingKey(), nameParser.getQueue(),
+ properties, attributes);
+ }
+ }
+
+ agent.methodResponse(methodName, handle, outArgs, null);
+ }
+ catch (Exception e)
+ {
+ agent.raiseException(handle, e.getMessage());
+ }
+ }
+ else // method = delete
+ {
+ try
+ {
+ if (type.equals("exchange")) // delete exchange.
+ {
+ Exchange exchange = nameParser.getExchange();
+ if (exchange != null)
+ {
+ exchange.delete();
+ }
+ }
+ else if (type.equals("queue")) // delete queue.
+ {
+ Queue queue = nameParser.getQueue();
+ if (queue != null)
+ {
+ queue.delete();
+ }
+ }
+ else if (type.equals("binding")) // delete binding.
+ {
+ Binding binding = nameParser.getBinding();
+ if (binding != null)
+ {
+ binding.delete();
+ }
+ }
+
+ agent.methodResponse(methodName, handle, outArgs, null);
+ }
+ catch (Exception e)
+ {
+ agent.raiseException(handle, e.getMessage());
+ }
+ }
+ }
+ }
+ else // If methodName is not create or delete.
+ {
+ agent.raiseException(handle, methodName + " not yet implemented on Broker.");
+ }
+ } // End of invokeMethod.
+
+ /**
+ * This method maps the org.apache.qpid.server.model.Broker to QMF2 broker properties where possible then
+ * serialises into the underlying Map for transmission via AMQP. This method is called by handleQueryRequest()
+ * in the org.apache.qpid.qmf2.agent.Agent class implementing the main QMF2 Agent behaviour.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ update(); // Need to do update before setting uptime in order to get the latest getUpdateTime() value.
+
+ // Not sure if there's an "official" broker uptime anywhere, but as the QmfManagementAgent is created when
+ // the broker is and the Broker object is created then too the following approach should be good enough.
+ setValue("uptime", getUpdateTime() - getCreateTime());
+
+ return super.mapEncode();
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Connection.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Connection.java
new file mode 100644
index 0000000000..9a96bfb493
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Connection.java
@@ -0,0 +1,203 @@
+/*
+ *
+ * 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.server.qmf2.agentdata;
+
+// Misc Imports
+import java.util.Map;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+//import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+//import org.apache.qpid.qmf2.common.SchemaProperty;
+
+
+/**
+ * This class provides a concrete implementation of QmfAgentData for the Connection Management Object.
+ * In general it's possible to use QmfAgentData without sub-classing as it's really a "bean" style class
+ * that retains its properties in a Map, but in the case of the Java Broker Management Agent it's useful
+ * to sub-class as we need to map between the properties/statistics as specified in the Java Broker
+ * management model and those specified in qpid/spec/management-schema.xml which is what the C++ broker
+ * uses. This class retains a reference to its peer org.apache.qpid.server.model.Connection and does the
+ * necessary mapping when its mapEncode() method is called (which is used to serialise the QmfAgentData).
+ *
+ * @author Fraser Adams
+ */
+public class Connection extends QmfAgentData
+{
+ private static final Logger _log = LoggerFactory.getLogger(Connection.class);
+
+ /**
+ * This static initialiser block initialises the QMF2 Schema information needed by the Agent to find
+ * QmfAgentData and QmfEvent Objects of a given type.
+ */
+ private static final SchemaObjectClass _schema;
+ private static final SchemaEventClass _clientConnectSchema;
+ private static final SchemaEventClass _clientDisconnectSchema;
+
+ /**
+ * Returns the schema for the Connection class.
+ * @return the SchemaObjectClass for the Connection class.
+ */
+ public static SchemaObjectClass getSchema()
+ {
+ return _schema;
+ }
+
+ /**
+ * Returns the schema for the Client Connect Event.
+ * @return the SchemaEventClass for the Client Connect Event.
+ */
+ public static SchemaEventClass getClientConnectSchema()
+ {
+ return _clientConnectSchema;
+ }
+
+ /**
+ * Returns the schema for the Client Disconnect Event.
+ * @return the SchemaEventClass for the Client Disconnect Event.
+ */
+ public static SchemaEventClass getClientDisconnectSchema()
+ {
+ return _clientDisconnectSchema;
+ }
+
+ static
+ {
+ // Declare the schema for the QMF2 connection class.
+ _schema = new SchemaObjectClass("org.apache.qpid.broker", "connection");
+
+ // TODO
+ //_schema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+
+ // Declare the schema for the QMF2 clientConnect Event class.
+ _clientConnectSchema = new SchemaEventClass("org.apache.qpid.broker", "clientConnect");
+
+ // Declare the schema for the QMF2 clientDisconnect Event class.
+ _clientDisconnectSchema = new SchemaEventClass("org.apache.qpid.broker", "clientDisconnect");
+ }
+ // End of static initialiser.
+
+ private final org.apache.qpid.server.model.Connection _connection;
+
+ /**
+ * Constructor.
+ * @param vhost the parent VirtualHost ConfiguredObject from the broker model.
+ * @param connection the Connection ConfiguredObject from the broker model.
+ */
+ public Connection(final org.apache.qpid.server.model.VirtualHost vhost,
+ final org.apache.qpid.server.model.Connection connection)
+ {
+ super(getSchema());
+ _connection = connection; // Will eventually be used to retrieve statistics (when useful ones get populated).
+ String vhostName = (vhost == null) ? "" : "vhost:" + vhost.getName() + "/";
+ String address = vhostName + _connection.getName();
+
+ // TODO vhostRef - currently just use its name to try and get things working with standard command line tools.
+
+ setValue("address", address);
+ setValue("incoming", true); // incoming not supported in Qpid 0.20
+
+ // Although not implemented in Qpid 0.20 it's reasonable for them to be false
+ setValue("SystemConnection", false); // Is the S in System really a capital? not implemented in Qpid 0.20
+ setValue("userProxyAuth", false); // Not implemented in Qpid 0.20
+ setValue("federationLink", false); // Not implemented in Qpid 0.20
+
+ setValue("authIdentity", connection.getAttribute("principal"));
+ setValue("remoteProcessName", "unknown"); // remoteProcessName not supported in Qpid 0.20
+ setValue("remotePid", "unknown"); // remoteProcessName not supported in Qpid 0.20
+ setValue("remoteParentPid", "unknown"); // remoteProcessName not supported in Qpid 0.20
+
+ // shadow Not implemented in Qpid 0.20
+ // saslMechanism Not implemented in Qpid 0.20
+ // saslSsf Not implemented in Qpid 0.20
+ // protocol Not implemented in Qpid 0.20
+ }
+
+ /**
+ * Factory method to create a Client Connect Event Object with timestamp of now.
+ * @return the newly created Client Connect Event Object.
+ */
+ public QmfEvent createClientConnectEvent()
+ {
+ QmfEvent clientConnect = new QmfEvent(_clientConnectSchema);
+ clientConnect.setSeverity("info");
+ // TODO Set properties Map - can't really get much info from the org.apache.qpid.server.model.Connection yet.
+ clientConnect.setValue("rhost", _connection.getName());
+ clientConnect.setValue("user", getStringValue("authIdentity"));
+ return clientConnect;
+ }
+
+ /**
+ * Factory method to create a Client Disconnect Event Object with timestamp of now.
+ * @return the newly created Client Disconnect Event Object.
+ */
+ public QmfEvent createClientDisconnectEvent()
+ {
+ QmfEvent clientDisconnect = new QmfEvent(_clientDisconnectSchema);
+ clientDisconnect.setSeverity("info");
+ // TODO Set properties Map - can't really get much info from the org.apache.qpid.server.model.Connection yet.
+ clientDisconnect.setValue("rhost", _connection.getName());
+ clientDisconnect.setValue("user", getStringValue("authIdentity"));
+ return clientDisconnect;
+ }
+
+ /**
+ * This method maps the org.apache.qpid.server.model.Connection to QMF2 broker properties where possible then
+ * serialises into the underlying Map for transmission via AMQP. This method is called by handleQueryRequest()
+ * in the org.apache.qpid.qmf2.agent.Agent class implementing the main QMF2 Agent behaviour.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+/*
+ // There isn't yet a way yet in the Java Broker to associate Connections->Sessions->Subscriptions->Queues
+ System.out.println("Connection name = " + _connection.getName());
+ for (org.apache.qpid.server.model.Session session : _connection.getSessions())
+ {
+ System.out.println("Session name = " + session);
+ }
+*/
+
+
+ // Statistics
+ //Statistics stats = _queue.getStatistics();
+ // closing Not implemented in Qpid 0.20
+ setValue("framesFromClient", 0); // framesFromClient Not implemented in Qpid 0.20
+ setValue("framesToClient", 0); // framesToClient Not implemented in Qpid 0.20
+ setValue("bytesFromClient", 0); // bytesFromClient Not implemented in Qpid 0.20
+ setValue("bytesToClient", 0); // bytesToClient Not implemented in Qpid 0.20
+ setValue("msgsFromClient", 0); // msgsFromClient Not implemented in Qpid 0.20
+ setValue("msgsToClient", 0); // msgsToClient Not implemented in Qpid 0.20
+
+ //update(); // TODO set update if statistics change.
+ return super.mapEncode();
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Exchange.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Exchange.java
new file mode 100644
index 0000000000..1f46daf99b
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Exchange.java
@@ -0,0 +1,252 @@
+/*
+ *
+ * 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.server.qmf2.agentdata;
+
+// Misc Imports
+import java.util.Collections;
+import java.util.Map;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+//import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+//import org.apache.qpid.qmf2.common.SchemaProperty;
+
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Statistics;
+
+/**
+ * This class provides a concrete implementation of QmfAgentData for the Exchange Management Object.
+ * In general it's possible to use QmfAgentData without sub-classing as it's really a "bean" style class
+ * that retains its properties in a Map, but in the case of the Java Broker Management Agent it's useful
+ * to sub-class as we need to map between the properties/statistics as specified in the Java Broker
+ * management model and those specified in qpid/spec/management-schema.xml which is what the C++ broker
+ * uses. This class retains a reference to its peer org.apache.qpid.server.model.Exchange and does the
+ * necessary mapping when its mapEncode() method is called (which is used to serialise the QmfAgentData).
+ *
+ * @author Fraser Adams
+ */
+public class Exchange extends QmfAgentData
+{
+ private static final Logger _log = LoggerFactory.getLogger(Exchange.class);
+
+ /**
+ * This static initialiser block initialises the QMF2 Schema information needed by the Agent to find
+ * QmfAgentData and QmfEvent Objects of a given type.
+ */
+ private static final SchemaObjectClass _schema;
+ private static final SchemaEventClass _exchangeDeclareSchema;
+ private static final SchemaEventClass _exchangeDeleteSchema;
+
+ /**
+ * Returns the schema for the Exchange class.
+ * @return the SchemaObjectClass for the Exchange class.
+ */
+ public static SchemaObjectClass getSchema()
+ {
+ return _schema;
+ }
+
+ /**
+ * Returns the schema for the Exchange Declare Event.
+ * @return the SchemaEventClass for the Exchange Declare Event.
+ */
+ public static SchemaEventClass getExchangeDeclareSchema()
+ {
+ return _exchangeDeclareSchema;
+ }
+
+ /**
+ * Returns the schema for the Exchange Delete Event.
+ * @return the SchemaEventClass for the Exchange Delete Event.
+ */
+ public static SchemaEventClass getExchangeDeleteSchema()
+ {
+ return _exchangeDeleteSchema;
+ }
+
+ static
+ {
+ // Declare the schema for the QMF2 broker class.
+ _schema = new SchemaObjectClass("org.apache.qpid.broker", "exchange");
+
+ // TODO
+ //_schema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+
+ // Declare the schema for the QMF2 exchangeDeclare Event class.
+ _exchangeDeclareSchema = new SchemaEventClass("org.apache.qpid.broker", "exchangeDeclare");
+
+ // Declare the schema for the QMF2 exchangeDelete Event class.
+ _exchangeDeleteSchema = new SchemaEventClass("org.apache.qpid.broker", "exchangeDelete");
+ }
+ // End of static initialiser.
+
+ private final org.apache.qpid.server.model.Exchange _exchange;
+ private String _name;
+
+ /**
+ * Constructor.
+ * @param vhost the parent VirtualHost ConfiguredObject from the broker model.
+ * @param exchange the Exchange ConfiguredObject from the broker model.
+ */
+ public Exchange(final org.apache.qpid.server.model.VirtualHost vhost,
+ final org.apache.qpid.server.model.Exchange exchange)
+ {
+ super(getSchema());
+ _exchange = exchange;
+
+ _name = _exchange.getName();
+ _name = (_name.equals("<<default>>")) ? "" : _name;
+
+ if (vhost == null)
+ { // Note we include an empty vhost name in the compare key to make sure things get sorted properly.
+ setCompareKey("vhost:/" + _name);
+ }
+ else
+ {
+ _name = "vhost:" + vhost.getName() + "/" + _name;
+ setCompareKey(_name);
+ }
+
+ LifetimePolicy lifetimePolicy = (LifetimePolicy)_exchange.getAttribute("lifetimePolicy");
+ boolean autoDelete = (lifetimePolicy == LifetimePolicy.AUTO_DELETE) ? true : false;
+
+ // TODO vhostRef - currently just use its name to try and get things working with standard command line tools.
+
+ setValue("name", _name);
+ setValue("type", _exchange.getAttribute("type"));
+ setValue("durable", _exchange.getAttribute("durable"));
+ setValue("autoDelete", autoDelete);
+
+ // TODO altExchange and arguments properties.
+
+ // ObjectId needs to be set here in Exchange because the QMF2 version of qpid-config uses a hardcoded
+ // _object_name as below in the _object_id that it sets in the getExchange() call and in exchangeRef.
+ // It *shouldn't* do this and should really use the _object_id of the exchange object returned by
+ // getObjects("exchange"), but it does. The following line causes the Agent to use the explicit
+ // ObjectId below rather than constructing its own, which fixes the qpid-config issue.
+ setObjectId(new ObjectId("", "org.apache.qpid.broker:exchange:" + _name, 0));
+ }
+
+ /**
+ * Get the peer org.apache.qpid.server.model.Exchange instance. This is mainly used when creating an Alternate
+ * Exchange on a Queue as the underlying method requires an org.apache.qpid.server.model.Exchange.
+ */
+ public org.apache.qpid.server.model.Exchange getExchange()
+ {
+ return _exchange;
+ }
+
+ /**
+ * Factory method to create an Exchange Declare Event Object with timestamp of now.
+ * @return the newly created Exchange Declare Event Object.
+ */
+ public QmfEvent createExchangeDeclareEvent()
+ {
+ QmfEvent exchangeDeclare = new QmfEvent(_exchangeDeclareSchema);
+ exchangeDeclare.setSeverity("info");
+ exchangeDeclare.setValue("altEx", ""); // Java Broker can't set Alternate Exchange on Exchange
+ exchangeDeclare.setValue("args", Collections.EMPTY_MAP);
+ exchangeDeclare.setValue("autoDel", getBooleanValue("autoDelete"));
+ exchangeDeclare.setValue("disp", "created");
+ exchangeDeclare.setValue("durable", getBooleanValue("durable"));
+ exchangeDeclare.setValue("exName", _name);
+ exchangeDeclare.setValue("exType", getStringValue("type"));
+ // TODO Not sure of a way to get these for Java Broker Exchange.
+ //exchangeDeclare.setValue("rhost", _connection.getName());
+ //exchangeDeclare.setValue("user", getStringValue("authIdentity"));
+ return exchangeDeclare;
+ }
+
+ /**
+ * Factory method to create an Exchange Delete Event Object with timestamp of now.
+ * @return the newly created Exchange Delete Event Object.
+ */
+ public QmfEvent createExchangeDeleteEvent()
+ {
+ QmfEvent exchangeDelete = new QmfEvent(_exchangeDeleteSchema);
+ exchangeDelete.setSeverity("info");
+ exchangeDelete.setValue("exName", _name);
+ // TODO Not sure of a way to get these for Java Broker Exchange.
+ //exchangeDelete.setValue("rhost", _connection.getName());
+ //exchangeDelete.setValue("user", getStringValue("authIdentity"));
+ return exchangeDelete;
+ }
+
+ /**
+ * This method maps the org.apache.qpid.server.model.Exchange to QMF2 broker properties where possible then
+ * serialises into the underlying Map for transmission via AMQP. This method is called by handleQueryRequest()
+ * in the org.apache.qpid.qmf2.agent.Agent class implementing the main QMF2 Agent behaviour.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ // Statistics
+ Statistics stats = _exchange.getStatistics();
+ long msgReceives = ((Long)stats.getStatistic("messagesIn")).longValue();
+ long msgDrops = ((Long)stats.getStatistic("messagesDropped")).longValue();
+ long msgRoutes = msgReceives - msgDrops;
+
+ long byteReceives = ((Long)stats.getStatistic("bytesIn")).longValue();
+ long byteDrops = ((Long)stats.getStatistic("bytesDropped")).longValue();
+ long byteRoutes = byteReceives - byteDrops;
+
+ setValue("producerCount", "Not yet implemented"); // In Qpid 0.20 producerCount statistic returns null.
+
+ // We have to modify the value of bindingCount for Exchange because the QmfManagementAgent "hides" the
+ // QMF Objects that relate to its own AMQP Connection/Queues/Bindings so the bindingCount for default direct
+ // qmf.default.direct and qmf.default.topic is different to the actual number of QMF bindings.
+ long bindingCount = ((Long)stats.getStatistic("bindingCount")).longValue();
+ if (_name.equals(""))
+ {
+ bindingCount -= 3;
+ }
+ else if (_name.equals("qmf.default.direct"))
+ {
+ bindingCount -= 2;
+ }
+ else if (_name.equals("qmf.default.topic"))
+ {
+ bindingCount -= 1;
+ }
+ setValue("bindingCount", bindingCount);
+
+ setValue("msgReceives", msgReceives);
+ setValue("msgDrops", msgDrops);
+ setValue("msgRoutes", msgRoutes);
+ setValue("byteReceives", byteReceives);
+ setValue("byteDrops", byteDrops);
+ setValue("byteRoutes", byteRoutes);
+
+ update(); // TODO only set update if a statistic has actually changed value.
+ return super.mapEncode();
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Queue.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Queue.java
new file mode 100644
index 0000000000..5cbe873769
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Queue.java
@@ -0,0 +1,287 @@
+/*
+ *
+ * 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.server.qmf2.agentdata;
+
+// Misc Imports
+import java.util.Collections;
+import java.util.Map;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.Agent;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+//import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+//import org.apache.qpid.qmf2.common.SchemaProperty;
+
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.Statistics;
+
+/**
+ * This class provides a concrete implementation of QmfAgentData for the Queue Management Object.
+ * In general it's possible to use QmfAgentData without sub-classing as it's really a "bean" style class
+ * that retains its properties in a Map, but in the case of the Java Broker Management Agent it's useful
+ * to sub-class as we need to map between the properties/statistics as specified in the Java Broker
+ * management model and those specified in qpid/spec/management-schema.xml which is what the C++ broker
+ * uses. This class retains a reference to its peer org.apache.qpid.server.model.Queue and does the
+ * necessary mapping when its mapEncode() method is called (which is used to serialise the QmfAgentData).
+ *
+ * @author Fraser Adams
+ */
+public class Queue extends QmfAgentData
+{
+ private static final Logger _log = LoggerFactory.getLogger(Queue.class);
+
+ /**
+ * This static initialiser block initialises the QMF2 Schema information needed by the Agent to find
+ * QmfAgentData and QmfEvent Objects of a given type.
+ */
+ private static final SchemaObjectClass _schema;
+ private static final SchemaEventClass _queueDeclareSchema;
+ private static final SchemaEventClass _queueDeleteSchema;
+
+ /**
+ * Returns the schema for the Queue class.
+ * @return the SchemaObjectClass for the Queue class.
+ */
+ public static SchemaObjectClass getSchema()
+ {
+ return _schema;
+ }
+
+ /**
+ * Returns the schema for the Queue Declare Event.
+ * @return the SchemaEventClass for the Queue Declare Event.
+ */
+ public static SchemaEventClass getQueueDeclareSchema()
+ {
+ return _queueDeclareSchema;
+ }
+
+ /**
+ * Returns the schema for the Queue Delete Event.
+ * @return the SchemaEventClass for the Queue Delete Event.
+ */
+ public static SchemaEventClass getQueueDeleteSchema()
+ {
+ return _queueDeleteSchema;
+ }
+
+ static
+ {
+ // Declare the schema for the QMF2 broker class.
+ _schema = new SchemaObjectClass("org.apache.qpid.broker", "queue");
+
+ // TODO
+ //_schema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+
+ // Declare the schema for the QMF2 queueDeclare Event class.
+ _queueDeclareSchema = new SchemaEventClass("org.apache.qpid.broker", "queueDeclare");
+
+ // Declare the schema for the QMF2 queueDelete Event class.
+ _queueDeleteSchema = new SchemaEventClass("org.apache.qpid.broker", "queueDelete");
+ }
+ // End of static initialiser.
+
+ private final org.apache.qpid.server.model.Queue _queue;
+ private String _vhostName = "";
+ private ObjectId _alternateExchange = null;
+ private String _alternateExchangeName = "";
+
+ /**
+ * Constructor.
+ * @param vhost the parent VirtualHost ConfiguredObject from the broker model.
+ * @param queue the Queue ConfiguredObject from the broker model.
+ */
+ public Queue(final org.apache.qpid.server.model.VirtualHost vhost,
+ final org.apache.qpid.server.model.Queue queue)
+ {
+ super(getSchema());
+ _queue = queue;
+
+ String name = _queue.getName();
+
+ if (vhost == null)
+ { // Note we include an empty vhost name in the compare key to make sure things get sorted properly.
+ setCompareKey("vhost:/" + name);
+ }
+ else
+ {
+ _vhostName = "vhost:" + vhost.getName() + "/";
+ name = _vhostName + name;
+ setCompareKey(name);
+ }
+
+ LifetimePolicy lifetimePolicy = (LifetimePolicy)_queue.getAttribute("lifetimePolicy");
+ boolean autoDelete = (lifetimePolicy == LifetimePolicy.AUTO_DELETE) ? true : false;
+
+ // TODO vhostRef - currently just use its name to try and get things working with standard command line tools.
+
+ setValue("name", name);
+ setValue("durable", _queue.getAttribute("durable"));
+ setValue("autoDelete", autoDelete);
+ setValue("exclusive", _queue.getAttribute("exclusive"));
+
+ // altExchange needs to be set later, done in mapEncode() for convenience, because it isn't set during
+ // Queue construction in the Java Broker.
+
+ // TODO arguments properties.
+
+
+ // ObjectId needs to be set here in Queue because the QMF2 version of qpid-config uses a hardcoded
+ // _object_name as below in the _object_id that it sets in the getQueue() call and in queueRef.
+ // It *shouldn't* do this and should really use the _object_id of the queue object returned by
+ // getObjects("queue"), but it does. The following line causes the Agent to use the explicit
+ // ObjectId below rather than constructing its own, which fixes the qpid-config issue.
+ setObjectId(new ObjectId("", "org.apache.qpid.broker:queue:" + name, 0));
+ }
+
+ /**
+ * TODO
+ *
+ */
+ public void invokeMethod(Agent agent, Handle handle, String methodName, QmfData inArgs)
+ {
+ /*if (methodName.equals("purge"))
+ {
+ //broker.create(inArgs);
+ }
+ else if (methodName.equals("reroute"))
+ {
+ //broker.create(inArgs);
+ }
+ else*/
+ {
+ agent.raiseException(handle, methodName + " not yet implemented on Queue.");
+ }
+ }
+
+ /**
+ * Factory method to create a Queue Declare Event Object with timestamp of now.
+ * @return the newly created Queue Declare Event Object.
+ */
+ public QmfEvent createQueueDeclareEvent()
+ {
+ QmfEvent queueDeclare = new QmfEvent(_queueDeclareSchema);
+ queueDeclare.setSeverity("info");
+ // TODO the _alternateExchangeName gets set some time after the Constructor - how do I get its value for
+ // the queueDeclareEvent???!!!
+ queueDeclare.setValue("altEx", _alternateExchangeName);
+ queueDeclare.setValue("args", Collections.EMPTY_MAP); // TODO
+ queueDeclare.setValue("autoDel", getBooleanValue("autoDelete"));
+ queueDeclare.setValue("disp", "created");
+ queueDeclare.setValue("durable", getBooleanValue("durable"));
+ queueDeclare.setValue("excl", getBooleanValue("durable"));
+ queueDeclare.setValue("qName", getStringValue("name"));
+ // TODO Not sure of a way to get these for Java Broker Exchange.
+ //queueDeclare.setValue("rhost", _connection.getName());
+ //queueDeclare.setValue("user", getStringValue("authIdentity"));
+ return queueDeclare;
+ }
+
+ /**
+ * Factory method to create a Queue Delete Event Object with timestamp of now.
+ * @return the newly created Queue Delete Event Object.
+ */
+ public QmfEvent createQueueDeleteEvent()
+ {
+ QmfEvent queueDelete = new QmfEvent(_queueDeleteSchema);
+ queueDelete.setSeverity("info");
+ queueDelete.setValue("qName", getStringValue("name"));
+ // TODO Not sure of a way to get these for Java Broker Exchange.
+ //queueDelete.setValue("rhost", _connection.getName());
+ //queueDelete.setValue("user", getStringValue("authIdentity"));
+ return queueDelete;
+ }
+
+ /**
+ * This method maps the org.apache.qpid.server.model.Queue to QMF2 broker properties where possible then
+ * serialises into the underlying Map for transmission via AMQP. This method is called by handleQueryRequest()
+ * in the org.apache.qpid.qmf2.agent.Agent class implementing the main QMF2 Agent behaviour.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ // Set the altExchange reference if an alternateExchange exists and hasn't already been set.
+ // Not sure how to set this closer to the Constructor. At the moment the _alternateExchangeName gets set
+ // too late to populate the "altEx" property of the queueDeclareEvent.
+ if (_alternateExchange == null)
+ {
+ Exchange altEx = (Exchange)_queue.getAttribute("alternateExchange");
+ if (altEx != null)
+ {
+ _alternateExchangeName = _vhostName + altEx.getName();
+ _alternateExchange = new ObjectId("", "org.apache.qpid.broker:exchange:" + _alternateExchangeName, 0);
+ setRefValue("altExchange", _alternateExchange);
+ }
+ }
+
+ // Statistics
+ Statistics stats = _queue.getStatistics();
+ setValue("msgTotalEnqueues", stats.getStatistic("totalEnqueuedMessages"));
+ setValue("msgTotalDequeues", stats.getStatistic("totalDequeuedMessages"));
+ // msgTxnEnqueues not implemented in Qpid 0.20
+ // msgTxnDequeues not implemented in Qpid 0.20
+ setValue("msgPersistEnqueues", stats.getStatistic("persistentEnqueuedMessages"));
+ setValue("msgPersistDequeues", stats.getStatistic("persistentDequeuedMessages"));
+ setValue("msgDepth", stats.getStatistic("queueDepthMessages"));
+ setValue("byteDepth", stats.getStatistic("queueDepthBytes"));
+ setValue("byteTotalEnqueues", stats.getStatistic("totalEnqueuedBytes"));
+ setValue("byteTotalDequeues", stats.getStatistic("totalDequeuedBytes"));
+ // byteTxnEnqueues not implemented in Qpid 0.20
+ // byteTxnDequeues not implemented in Qpid 0.20
+ setValue("bytePersistEnqueues", stats.getStatistic("persistentEnqueuedBytes"));
+ setValue("bytePersistDequeues", stats.getStatistic("persistentDequeuedBytes"));
+
+ // Flow-to-disk Statistics not implemented in Qpid 0.20
+ // releases & acquires not implemented in Qpid 0.20
+ // discardsTtl (discardsTtlMessages) not implemented in Qpid 0.20
+ // discardsRing not implemented in Qpid 0.20
+ // discardsLvq not implemented in Qpid 0.20
+ // discardsOverflow not implemented in Qpid 0.20
+ // discardsSubscriber not implemented in Qpid 0.20
+ // discardsPurge not implemented in Qpid 0.20
+ // reroutes not implemented in Qpid 0.20
+
+ setValue("consumerCount", stats.getStatistic("consumerCount"));
+ setValue("bindingCount", stats.getStatistic("bindingCount"));
+ setValue("unackedMessages", stats.getStatistic("unacknowledgedMessages"));
+
+ setValue("messageLatency", "Not yet implemented");
+ // flowStopped not implemented in Qpid 0.20
+ // flowStoppedCount not implemented in Qpid 0.20
+
+ update(); // TODO only update if statistics have actually changed.
+ return super.mapEncode();
+ }
+}
diff --git a/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Subscription.java b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Subscription.java
new file mode 100644
index 0000000000..028059f64b
--- /dev/null
+++ b/qpid/tools/src/java/src/qpid-broker-plugins-management-qmf2/java/org/apache/qpid/server/qmf2/agentdata/Subscription.java
@@ -0,0 +1,207 @@
+/*
+ *
+ * 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.server.qmf2.agentdata;
+
+// Misc Imports
+import java.util.Collections;
+import java.util.Map;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+//import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+//import org.apache.qpid.qmf2.common.SchemaProperty;
+
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.Statistics;
+
+/**
+ * This class provides a concrete implementation of QmfAgentData for the Subscription Management Object.
+ * In general it's possible to use QmfAgentData without sub-classing as it's really a "bean" style class
+ * that retains its properties in a Map, but in the case of the Java Broker Management Agent it's useful
+ * to sub-class as we need to map between the properties/statistics as specified in the Java Broker
+ * management model and those specified in qpid/spec/management-schema.xml which is what the C++ broker
+ * uses. This class retains a reference to its peer org.apache.qpid.server.model.Consumer and does the
+ * necessary mapping when its mapEncode() method is called (which is used to serialise the QmfAgentData).
+ *
+ * @author Fraser Adams
+ */
+public class Subscription extends QmfAgentData
+{
+ private static final Logger _log = LoggerFactory.getLogger(Subscription.class);
+
+ /**
+ * This static initialiser block initialises the QMF2 Schema information needed by the Agent to find
+ * QmfAgentData and QmfEvent Objects of a given type.
+ */
+ private static final SchemaObjectClass _schema;
+ private static final SchemaEventClass _subscribeSchema;
+ private static final SchemaEventClass _unsubscribeSchema;
+
+ /**
+ * Returns the schema for the Subscription class.
+ * @return the SchemaObjectClass for the Subscription class.
+ */
+ public static SchemaObjectClass getSchema()
+ {
+ return _schema;
+ }
+
+ /**
+ * Returns the schema for the Subscribe Event.
+ * @return the SchemaEventClass for the Subscribe Event.
+ */
+ public static SchemaEventClass getSubscribeSchema()
+ {
+ return _subscribeSchema;
+ }
+
+ /**
+ * Returns the schema for the Unsubscribe Event.
+ * @return the SchemaEventClass for the Unsubscribe Event.
+ */
+ public static SchemaEventClass getUnsubscribeSchema()
+ {
+ return _unsubscribeSchema;
+ }
+
+ static
+ {
+ // Declare the schema for the QMF2 subscription class.
+ _schema = new SchemaObjectClass("org.apache.qpid.broker", "subscription");
+
+ // TODO
+ //_schema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+
+ // Declare the schema for the QMF2 subscribe Event class.
+ _subscribeSchema = new SchemaEventClass("org.apache.qpid.broker", "subscribe");
+
+ // Declare the schema for the QMF2 unsubscribe Event class.
+ _unsubscribeSchema = new SchemaEventClass("org.apache.qpid.broker", "unsubscribe");
+ }
+ // End of static initialiser.
+
+ private final org.apache.qpid.server.model.Consumer _subscription;
+
+ private boolean _exclusive = false;
+ private String _qName = "";
+
+ /**
+ * Constructor.
+ * @param subscription the Consumer ConfiguredObject from the broker model.
+ */
+ public Subscription(final org.apache.qpid.server.model.Consumer subscription)
+ {
+ super(getSchema());
+ _subscription = subscription; // Will eventually be used in mapEncode() to retrieve statistics.
+
+ setValue("name", subscription.getName());
+ setValue("browsing", false); // TODO not supported in Qpid 0.20.
+ setValue("acknowledged", true); // TODO not supported in Qpid 0.20.
+ setValue("creditMode", "WINDOW"); // TODO not supported in Qpid 0.20.
+ }
+
+ /**
+ * Set the sessionRef property.
+ * @param sessionRef the sessionRef ObjectId.
+ */
+ public void setSessionRef(final ObjectId sessionRef)
+ {
+ setRefValue("sessionRef", sessionRef);
+ }
+
+ /**
+ * Set the queueRef property.
+ * @param queueRef the queueRef ObjectId.
+ */
+ public void setQueueRef(final ObjectId queueRef, final Queue queue)
+ {
+ setRefValue("queueRef", queueRef);
+
+ // Unfortunately the org.apache.qpid.server.model.Consumer doesn't yet allow access to its associated Queue
+ // so we pass a reference ourselves when we do setQueueRef. This is because some Subscription properties
+ // are *actually" related to the associated Queue.
+ _qName = queue.getName();
+ _exclusive = ((Boolean)queue.getAttribute("exclusive")).booleanValue();
+ }
+
+ /**
+ * Factory method to create a Subscribe Event Object with timestamp of now.
+ * @return the newly created Subscribe Event Object.
+ */
+ public QmfEvent createSubscribeEvent()
+ {
+ QmfEvent subscribe = new QmfEvent(_subscribeSchema);
+ subscribe.setSeverity("info");
+ subscribe.setValue("args", Collections.EMPTY_MAP);
+ subscribe.setValue("dest", getStringValue("name"));
+ subscribe.setValue("excl", _exclusive);
+ subscribe.setValue("qName", _qName);
+ // TODO Not sure of a way to get these for Java Broker Subscription.
+ //subscribe.setValue("rhost", _connection.getName());
+ //subscribe.setValue("user", getStringValue("authIdentity"));
+ return subscribe;
+ }
+
+ /**
+ * Factory method to create an Unsubscribe Event Object with timestamp of now.
+ * @return the newly created Unsubscribe Event Object.
+ */
+ public QmfEvent createUnsubscribeEvent()
+ {
+ QmfEvent unsubscribe = new QmfEvent(_unsubscribeSchema);
+ unsubscribe.setSeverity("info");
+ unsubscribe.setValue("dest", getStringValue("name"));
+ // TODO Not sure of a way to get these for Java Broker Subscription.
+ //unsubscribe.setValue("rhost", _connection.getName());
+ //unsubscribe.setValue("user", getStringValue("authIdentity"));
+ return unsubscribe;
+ }
+
+ /**
+ * This method maps the org.apache.qpid.server.model.Consumer to QMF2 subscribe properties where possible then
+ * serialises into the underlying Map for transmission via AMQP. This method is called by handleQueryRequest()
+ * in the org.apache.qpid.qmf2.agent.Agent class implementing the main QMF2 Agent behaviour.
+ *
+ * @return the underlying map.
+ */
+ @Override
+ public Map<String, Object> mapEncode()
+ {
+ // Statistics
+ Statistics stats = _subscription.getStatistics();
+ setValue("delivered", stats.getStatistic("messagesOut"));
+
+ setValue("exclusive", _exclusive);
+
+ update(); // TODO Only Update if statistics have changes.
+ return super.mapEncode();
+ }
+}
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionProxy.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionProxy.java
new file mode 100644
index 0000000000..435372a0d6
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionProxy.java
@@ -0,0 +1,287 @@
+/*
+ *
+ * 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.restapi;
+
+// Misc Imports
+import java.util.TimerTask;
+
+// JMS Imports
+import javax.jms.Connection;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.BlockingNotifier;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+
+/**
+ * Contains a Connection object under a "leasehold agreement" whereby the Connection (and associated Sessions and QMF
+ * Consoles) will expire after a period of time.
+ * <p>
+ * The idea here is to allow a user to create multiple Connection instances (for example to monitor multiple brokers)
+ * but by using the lease metaphor we can expire instances that haven't been used for some predetermined period.
+ * Using the leashold agreement means that we don't have to rely on users explicitly deleting Connections that they
+ * are no longer interested in, because obviously we can't rely on that :-)
+ *
+ * @author Fraser Adams
+ */
+public final class ConnectionProxy extends TimerTask implements ExceptionListener
+{
+ private static final Logger _log = LoggerFactory.getLogger(ConnectionProxy.class);
+
+ private static final int MAX_WORKITEM_QUEUE_SIZE = 20; // Maximum number of items allowed on WorkItem queue.
+
+ // Connections expire after 20 minutes of no use.
+ private static final int TIMEOUT_THRESHOLD = (20*60000)/ConnectionStore.PING_PERIOD;
+
+ // Connections expire after 1 minute if they have never been dereferenced.
+ private static final int UNUSED_THRESHOLD = 60000/ConnectionStore.PING_PERIOD;
+
+ private Connection _connection;
+ private Console _console;
+ private boolean _connected;
+ private int _expireCount;
+ private final ConnectionStore _store;
+ private final String _name;
+ private final String _url;
+ private final String _connectionOptions;
+ private final boolean _disableEvents;
+
+ /**
+ * Actually create the Qpid Connection and QMF2 Console specified in the Constructor.
+ */
+ private synchronized void createConnection()
+ {
+ //System.out.println("ConnectionProxy createConnection() name: " + _name + ", thread: " + Thread.currentThread().getId() + ", creating connection to " + _url + ", options " + _connectionOptions);
+ try
+ {
+ _connection = ConnectionHelper.createConnection(_url, _connectionOptions);
+ if (_connection != null)
+ {
+ _connection.setExceptionListener(this);
+
+ // N.B. creating a Console with a notifier causes the internal WorkQueue to get populated, so care must
+ // be taken to manage its size. In a normal Console application the application would only declare this
+ // if there was an intention to retrieve work items, but in a fairly general REST API we can't guarantee
+ // that clients will. ConsoleLease acts to make the WorkQueue "circular" by deleting items from the
+ // front of the WorkQueue if it exceeds a particular size.
+ if (_disableEvents)
+ {
+ _console = new Console(_name, null, null, null);
+ _console.disableEvents();
+ }
+ else
+ {
+ BlockingNotifier notifier = new BlockingNotifier();
+ _console = new Console(_name, null, notifier, null);
+ }
+ _console.addConnection(_connection);
+ _connected = true;
+ _expireCount = UNUSED_THRESHOLD;
+ notifyAll();
+ }
+ }
+ catch (Exception ex)
+ {
+ _log.info("Exception {} caught in ConnectionProxy constructor.", ex.getMessage());
+ _connected = false;
+ }
+ }
+
+ /**
+ * This method blocks until the Connection has been created.
+ */
+ public synchronized void waitForConnection()
+ {
+ while (!_connected)
+ {
+ try
+ {
+ wait();
+ }
+ catch (InterruptedException ie)
+ {
+ continue;
+ }
+ }
+ }
+
+ /**
+ * This method blocks until the Connection has been created or timeout expires (or wait has been interrupted).
+ * @param timeout the maximum time in milliseconds to wait for notification of the connection's availability.
+ */
+ public synchronized void waitForConnection(long timeout)
+ {
+ try
+ {
+ wait(timeout);
+ }
+ catch (InterruptedException ie)
+ { // Ignore
+ }
+ }
+
+ /**
+ * Construct a Proxy to the specified Qpid Connection with the supplied name to be stored in the specified store.
+ * @param store The ConnectionStore that we want to store this ConnectionProxy in.
+ * @param name A unique name for the Connection that we want to create.
+ * @param url A Connection URL using one of the forms supported by {@link org.apache.qpid.qmf2.util.ConnectionHelper}.
+ * @param connectionOptions A set of connection options in the form supported by {@link org.apache.qpid.qmf2.util.ConnectionHelper}.
+ * @param disableEvents if true create a QMF Console Connection that can only perform synchronous
+ * operations like getObjects() and cannot do asynchronous things like Agent discovery or receive Events.
+ */
+ public ConnectionProxy(final ConnectionStore store, final String name,
+ final String url, final String connectionOptions, final boolean disableEvents)
+ {
+ _connected = false;
+ _store = store;
+ _name = name;
+ _url = url;
+ _connectionOptions = connectionOptions;
+ _disableEvents = disableEvents;
+ }
+
+ /**
+ * The exception listener for the underlying Qpid Connection. This is used to trigger the ConnectionProxy internal
+ * reconnect logic. N.B. ConnectionProxy uses its own reconnection logic for two reasons: firstly the Qpid auto
+ * retry mechanism has some undesireable and unreliable behaviours prior to Qpid version 0.16 and secondly the
+ * Qpid auto retry mechanism is transparent whereas we actually <b>want</b> to detect connection failures in the REST
+ * API so that we can report failures back to the client.
+ * @param jmse The JMSException that has caused onException to be triggered.
+ */
+ public void onException(JMSException jmse)
+ {
+ _log.info("ConnectionProxy onException {}", jmse.getMessage());
+ _connected = false;
+ }
+
+ /**
+ * This method is called periodically by {@link org.apache.qpid.restapi.ConnectionStore} to carry out a number
+ * of housekeeping tasks. It checks if the Qpid Connection is still connected and if not it attempts to reconnect
+ * it also checks whether the Connection "lease" has run out and if it has it tidies up the Connection. Finally
+ * it restricts the size of the QMF2 WorkItem queue as the REST API has no control over whether a client is or
+ * is not interested in being notified of QMF2 Events.
+ */
+ public void run()
+ {
+ if (_connected)
+ {
+ //System.out.println("ConnectionProxy name: " + _name + ", thread: " + Thread.currentThread().getId() + ", WorkItem count = " + _console.getWorkitemCount());
+
+ while (_console.getWorkitemCount() > MAX_WORKITEM_QUEUE_SIZE)
+ {
+ _console.getNextWorkitem();
+ }
+
+ _expireCount--;
+ //System.out.println("ConnectionProxy name: " + _name + ", thread: " + Thread.currentThread().getId() + ", expireCount = " + _expireCount);
+ if (_expireCount == 0)
+ {
+ _store.delete(_name);
+ }
+ }
+ else
+ {
+ createConnection();
+ }
+ }
+
+ /**
+ * Stops scheduled housekeeping, destroys any attached QMF2 Console instances then closes the Qpid Connection.
+ */
+ public synchronized void close()
+ {
+ //System.out.println("ConnectionProxy close() name: " + _name + ", thread: " + Thread.currentThread().getId() + ", expireCount = " + _expireCount);
+
+ cancel();
+
+ try
+ {
+ _console.destroy();
+ _connection.close();
+ }
+ catch (Exception e)
+ { // Log and Ignore
+ _log.info("ConnectionProxy close() caught Exception {}", e.getMessage());
+ }
+ }
+
+ /**
+ * Retrieves the QMF2 Console that we've associated with this Connection.
+ * @return The QMF2 Console that we've associated with this Connection.
+ */
+ public Console getConsole()
+ {
+ _expireCount = TIMEOUT_THRESHOLD;
+ return _console;
+ }
+
+ /**
+ * Returns whether or not the Connection is currently connected to the broker. This is used by the REST API to
+ * tell any clients about the Connection state.
+ * @return true if currently connected or false if not.
+ */
+ public boolean isConnected()
+ {
+ _expireCount = TIMEOUT_THRESHOLD;
+ return _connected;
+ }
+
+ /**
+ * Returns the Connection URL String used to create the Connection.
+ * @return The Connection URL String used to create the Connection.
+ */
+ public String getUrl()
+ {
+ _expireCount = TIMEOUT_THRESHOLD;
+ return _url;
+ }
+
+ /**
+ * Returns the Connection options String used to create the Connection.
+ * @return The Connection options String used to create the Connection.
+ */
+ public String getConnectionOptions()
+ {
+ _expireCount = TIMEOUT_THRESHOLD;
+ return _connectionOptions;
+ }
+
+ /**
+ * Returns a String representation of a ConnectionProxy.
+ * @return The String representation of this ConnectionProxy Object.
+ */
+ @Override
+ public String toString()
+ {
+ // The reason we use JSON.toMap on the string is because it is fairly tolerant and doesn't need pure JSON
+ // if we then call JSON.fromMap we get a pure JSON String.
+ return "{" + "\"url\":\"" + _url + "\",\"connectionOptions\":" +
+ JSON.fromMap(JSON.toMap(_connectionOptions)) + "}";
+ }
+}
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionStore.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionStore.java
new file mode 100644
index 0000000000..79b85c9c42
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/ConnectionStore.java
@@ -0,0 +1,138 @@
+/*
+ *
+ * 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.restapi;
+
+// Misc Imports
+import java.util.Map;
+import java.util.Timer;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.console.Console;
+
+/**
+ * A ConnectionStore is a container for Qpid Connection Objects, or rather it's a container for ConnectionProxy
+ * Objects which wrap Qpid Connections and provide some additional housekeeping behaviour necessary for a distributed
+ * system. The ConnectionStore schedules regular housekeeping tasks to be executed on the ConnectionProxy Objects
+ * using a java.util.Timer, which scales fairly well.
+ *
+ * @author Fraser Adams
+ */
+public class ConnectionStore
+{
+ /**
+ * This represents the time between "pings" to the stored ConnectionProxy Objects. The pings run scheduled tasks
+ * such as attempting reconnection if the broker has disconnected and checking lease timeouts.
+ */
+ public static final int PING_PERIOD = 5000;
+
+ /**
+ * This Map is used to associate connection names with their ConnectionProxies. Note that the names are prefixed
+ * internally with the authenticated user name to prevent users accidentally (or maliciously) sharing connections.
+ */
+ private Map<String, ConnectionProxy> _connections = new ConcurrentHashMap<String, ConnectionProxy>();
+
+ /**
+ * Create a Timer used to schedule regular checks on ConnectionProxy Objects to see that they are still in use.
+ * In essence ConnectionProxy Objects behave in a similar way to RMI Leases in that if they are not used
+ * (dereferenced) within a particular period it is assumed that the client has lost interest and they are reaped.
+ */
+ private Timer _timer = new Timer(true);
+
+ /**
+ * Creates a new ConnectionProxy Object with the given name, which in turn creates a Qpid Connection using the
+ * supplied Connection URL and options. In addition it schedules some regular housekeeping on the ConnectionProxy
+ * to enable it to manage Connection failures and perform what amounts to distributed garbage collection.
+ * When a ConnectionProxy with a given name has been created it is cached and subsequent calls to this method
+ * will return the cached instance. If an new instance is required one must first call the delete method.
+ * @param name A unique name for the Connection that we want to create.
+ * @param url A Connection URL using one of the forms supported by {@link org.apache.qpid.qmf2.util.ConnectionHelper}.
+ * @param opts A set of connection options in the form supported by {@link org.apache.qpid.qmf2.util.ConnectionHelper}.
+ * @param disableEvents if true create a QMF Console Connection that can only perform synchronous
+ * operations like getObjects() and cannot do asynchronous things like Agent discovery or receive Events.
+ * @return the ConnectionProxy Object created or cached by this method.
+ */
+ public synchronized ConnectionProxy create(final String name, final String url, final String opts,
+ final boolean disableEvents)
+ {
+ ConnectionProxy connection = _connections.get(name);
+ if (connection == null)
+ {
+ connection = new ConnectionProxy(this, name, url, opts, disableEvents);
+ _connections.put(name, connection);
+ _timer.schedule(connection, 0, PING_PERIOD);
+ }
+ return connection;
+ }
+
+ /**
+ * Closes the named Connection, stops its scheduled housekeeping and removes from the store.
+ * @param name the name of the Connection that we want to delete.
+ */
+ public synchronized void delete(final String name)
+ {
+ ConnectionProxy connection = _connections.get(name);
+ if (connection != null)
+ {
+ connection.close();
+ _connections.remove(name);
+ }
+ }
+
+ /**
+ * Retrieves the named Connection from the store.
+ * @param name the name of the Connection that we want to retrieve.
+ * @return the ConnectionProxy instance with the given name.
+ */
+ public ConnectionProxy get(final String name)
+ {
+ return _connections.get(name);
+ }
+
+ /**
+ * Return a Map of ConnectionProxies associated with a given user. Note that this method is fairly inefficient
+ * as the main _connections Map contains all ConnectionProxies and we normally do a lookup by prefixing the
+ * key with the user name in order to demultiplex. It is done this way as we need to look up ConnectionProxy
+ * for each API call, whereas looking up all Connections for a user is likely to be rarely called.
+ * @param user the security principal associated with a particular user.
+ * @return a Map of ConnectionProxy objects associated with the given user.
+ */
+ public Map<String, ConnectionProxy> getAll(final String user)
+ {
+ Map<String, ConnectionProxy> map = new ConcurrentHashMap<String, ConnectionProxy>();
+ String prefix = user + ".";
+ int prefixLength = prefix.length();
+ for (Map.Entry<String, ConnectionProxy> entry : _connections.entrySet())
+ {
+ String key = entry.getKey();
+ if (key.startsWith(prefix))
+ {
+ key = key.substring(prefixLength);
+ ConnectionProxy value = entry.getValue();
+ map.put(key, value);
+ }
+ }
+ return map;
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/FileServer.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/FileServer.java
new file mode 100644
index 0000000000..2cbb1140b1
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/FileServer.java
@@ -0,0 +1,369 @@
+/*
+ *
+ * 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.restapi;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
+import static java.net.HttpURLConnection.HTTP_PARTIAL;
+import static java.net.HttpURLConnection.HTTP_MOVED_PERM;
+import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
+import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
+import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
+
+/**
+ * FileServer is a fairly simple HTTP File Server that can be used to serve files from the root directory specified
+ * during construction.
+ * <p>
+ * Although this is a relatively simple File Server it is still able to serve large files as it uses streaming, in
+ * addition it uses the HTTP Range/Content-Range/Content-Length Headers to allow resuming of partial downloads
+ * from clients that support it.
+ *
+ * @author Fraser Adams
+ */
+public class FileServer implements Server
+{
+ /**
+ * HashMap mapping file extension to MIME type for common types.
+ * TODO make this set of mappings configurable via properties or similar mechanism.
+ */
+ private static Map<String, String> _mimeTypes = new HashMap<String, String>();
+ static
+ {
+ _mimeTypes.put("htm", "text/html");
+ _mimeTypes.put("html", "text/html");
+ _mimeTypes.put("txt", "text/plain");
+ _mimeTypes.put("asc", "text/plain");
+ _mimeTypes.put("xml", "text/xml");
+ _mimeTypes.put("css", "text/css");
+ _mimeTypes.put("htc", "text/x-component");
+ _mimeTypes.put("gif", "image/gif");
+ _mimeTypes.put("jpg", "image/jpeg");
+ _mimeTypes.put("jpeg", "image/jpeg");
+ _mimeTypes.put("png", "image/png");
+ _mimeTypes.put("ico", "image/x-icon");
+ _mimeTypes.put("mp3", "audio/mpeg");
+ _mimeTypes.put("m3u", "audio/mpeg-url");
+ _mimeTypes.put("js", "application/x-javascript");
+ _mimeTypes.put("pdf", "application/pdf");
+ _mimeTypes.put("doc", "application/msword");
+ _mimeTypes.put("ppt", "application/mspowerpoint");
+ _mimeTypes.put("xls", "application/excel");
+ _mimeTypes.put("ogg", "application/x-ogg");
+ _mimeTypes.put("zip", "application/octet-stream");
+ _mimeTypes.put("exe", "application/octet-stream");
+ _mimeTypes.put("class", "application/octet-stream");
+ }
+
+ private final File _home;
+ private final boolean _allowDirectoryListing;
+
+ /**
+ * URL-encodes everything between "/"-characters. Encodes spaces as '%20' instead of '+'.
+ *
+ * @param uri the uri to be encoded.
+ * @return the encoded uri as a String.
+ */
+ private String encodeUri(final String uri)
+ {
+ StringBuilder encodedUri = new StringBuilder();
+ StringTokenizer st = new StringTokenizer(uri, "/ ", true);
+ while (st.hasMoreTokens())
+ {
+ String tok = st.nextToken();
+ if (tok.equals("/"))
+ {
+ encodedUri.append("/");
+ }
+ else if (tok.equals(" "))
+ {
+ encodedUri.append("%20");
+ }
+ else
+ {
+ try
+ {
+ encodedUri.append(URLEncoder.encode(tok, "UTF-8"));
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ }
+ }
+ }
+ return encodedUri.toString();
+ }
+
+ /**
+ * Renders a number in a more "human readable" format providing a bytes/KB/MB/GB format depending on the size.
+ *
+ * @param number the number to be rendered.
+ * @return a String representation of the number in a more human readable form.
+ */
+ private String renderNumber(float number)
+ {
+ if (number < 1000)
+ {
+ return String.format("%.0f", number) + " bytes";
+ }
+ else if (number < 1000000)
+ {
+ number /= 1000.0f;
+ return String.format("%.1f", number) + " KB";
+ }
+ else if (number < 1000000000)
+ {
+ number /= 1000000.0f;
+ return String.format("%.1f", number) + " MB";
+ }
+ else
+ {
+ number /= 1000000000.0f;
+ return String.format("%.1f", number) + " GB";
+ }
+ }
+
+ /**
+ * Construct an instance of FileServer.
+ *
+ * @param home the path name of the root directory that we wish this FieServer to serve via HTTP.
+ * @param allowDirectoryListing a flag that if set will serve a directory listing to the client and thus enable
+ * browsing to sub-directories of the home directory. N.B. protection has been put in place to mitigate
+ * against the possibility of serving directories that may be parents of the root directory.
+ */
+ public FileServer(final String home, final boolean allowDirectoryListing)
+ {
+ _home = new File(home);
+ _allowDirectoryListing = allowDirectoryListing;
+ }
+
+ /**
+ * Called by the Web Server to allow a Server to handle a GET request.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doGet(final HttpTransaction tx) throws IOException
+ {
+ String user = tx.getPrincipal() != null ? tx.getPrincipal() : "none";
+ String path = tx.getRequestURI();
+
+ //System.out.println();
+ //System.out.println("FileServer doGet " + path + ", user: " + user);
+ //System.out.println("thread = " + Thread.currentThread().getId());
+ //tx.logRequest();
+
+ // If the _home filesystem that we use as a root to serve files from is not a directory then
+ // we sent an error response and return.
+ if (!_home.isDirectory())
+ {
+ tx.sendResponse(HTTP_INTERNAL_ERROR, "text/plain",
+ "500 Internal Server Error: given document root is not a directory.");
+ return;
+ }
+
+ //String path = tx.getRequestURI();
+
+ // Prohibit getting out of _home directory
+ if (path.startsWith("..") || path.endsWith("..") || path.indexOf("../") >= 0)
+ {
+ tx.sendResponse(HTTP_FORBIDDEN, "text/plain", "403 Forbidden: Won't serve ../ for security reasons.");
+ return;
+ }
+
+ File file = new File(_home, path);
+ if (!file.exists())
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found: File " + path + " not found.");
+ return;
+ }
+
+ // List the directory, if necessary
+ if (file.isDirectory())
+ {
+ File directory = file;
+ // Browsers get confused without '/' after the directory, send a redirect.
+ if (!path.endsWith("/"))
+ {
+ path += "/";
+ tx.setHeader("Location", path);
+ tx.sendResponse(HTTP_MOVED_PERM, "text/html",
+ "<html><body>Redirected: <a href=\"" + path + "\">" + path + "</a></body></html>");
+ return;
+ }
+
+ // First try index.html and index.htm
+ if (new File(directory, "index.html").exists())
+ {
+ file = new File(_home, path + "/index.html");
+ }
+ else if (new File(directory, "index.htm").exists())
+ {
+ file = new File(_home, path + "/index.htm");
+ }
+ else if (_allowDirectoryListing)
+ { // No index file, list the directory
+ StringBuilder response = new StringBuilder("<html><body><h1>Directory " + path + "</h1><br/>");
+
+ if (path.length() > 1)
+ {
+ String u = path.substring(0, path.length() - 1);
+ int slash = u.lastIndexOf('/');
+ if (slash >= 0 && slash < u.length())
+ {
+ response.append("<b><a href=\"" + path.substring(0, slash + 1) + "\">..</a></b><br/>");
+ }
+ }
+
+ String[] files = directory.list();
+ for (String name : files)
+ {
+ File current = new File(directory, name);
+ boolean isDir = current.isDirectory();
+ boolean isFile = current.isFile();
+ if (isDir)
+ {
+ response.append("<b>");
+ name += "/";
+ }
+
+ response.append("<a href=\"" + encodeUri(path + name) + "\">" + name + "</a>");
+
+ if (isFile)
+ { // If it's a file show the file size
+ response.append(" &nbsp;<font size=2>(" + renderNumber(current.length()) + ")</font>");
+ }
+ response.append("<br/>");
+ if (isDir)
+ {
+ response.append("</b>");
+ }
+ }
+ tx.sendResponse(HTTP_OK, "text/html", response.toString());
+ return;
+ }
+ else
+ {
+ tx.sendResponse(HTTP_FORBIDDEN, "text/plain", "403 Forbidden: No directory listing.");
+ return;
+ }
+ }
+
+ try
+ {
+ // Get MIME type from file name extension, if possible
+ String fileName = file.getCanonicalPath();
+ String mime = null;
+ int dot = fileName.lastIndexOf('.');
+ if (dot >= 0)
+ {
+ String fileExtension = fileName.substring(dot + 1).toLowerCase();
+ mime = _mimeTypes.get(fileExtension);
+ }
+
+ if (mime == null)
+ {
+ mime = "application/octet-stream";
+ }
+
+ // Use Range header allow download resuming.
+ long startFrom = 0;
+ long length = file.length();
+
+ String range = tx.getHeader("Range");
+ if (range != null)
+ {
+ if (range.startsWith("bytes="))
+ {
+ range = range.substring("bytes=".length());
+
+ int minus = range.indexOf('-');
+ if (minus > 0)
+ {
+ range = range.substring(0, minus);
+ }
+
+ try
+ {
+ startFrom = Long.parseLong(range);
+ }
+ catch (NumberFormatException nfe)
+ {
+ }
+ }
+ }
+
+ FileInputStream is = new FileInputStream(file);
+ is.skip(startFrom);
+
+ int status = (startFrom == 0) ? HTTP_OK : HTTP_PARTIAL;
+ tx.setHeader("Content-Length", "" + (length - startFrom));
+ tx.setHeader("Content-Range", "" + startFrom + "-" + (length - 1) + "/" + length);
+
+ tx.sendResponse(status, mime, is);
+ }
+ catch (IOException ioe)
+ {
+ tx.sendResponse(HTTP_FORBIDDEN, "text/plain", "403 Forbidden: Reading file failed.");
+ }
+ }
+
+ /**
+ * Called by the Web Server to allow a Server to handle a POST request.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doPost(final HttpTransaction tx) throws IOException
+ {
+ tx.sendResponse(HTTP_BAD_METHOD, "text/plain", "405 Bad Method.");
+ }
+
+ /**
+ * Called by the Web Server to allow a Server to handle a PUT request.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doPut(final HttpTransaction tx) throws IOException
+ {
+ tx.sendResponse(HTTP_BAD_METHOD, "text/plain", "405 Bad Method.");
+ }
+
+ /**
+ * Called by the Web Server to allow a Server to handle a DELETE request.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doDelete(final HttpTransaction tx) throws IOException
+ {
+ tx.sendResponse(HTTP_BAD_METHOD, "text/plain", "405 Bad Method.");
+ }
+}
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/HttpTransaction.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/HttpTransaction.java
new file mode 100644
index 0000000000..323ba29861
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/HttpTransaction.java
@@ -0,0 +1,165 @@
+/*
+ *
+ * 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.restapi;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * An HttpTransaction encapsulates an HTTP request received and a response to be generated in one HTTP request/response
+ * "transaction". It provides methods for examining the request from the client, and for building and sending the
+ * response from the server.
+ * <p>
+ * Note that the HttpTransaction interface isn't intended to be completely general, rather it is intended to abstract
+ * the services needed in org.apache.qpid.restapi in such a way as to be neutral as to whether the Web Server is
+ * based on com.sun.net.httpserver.HttpServer or javax.servlet.http.HttpServlet.
+ * <p>
+ * The Server and HttpTransaction interfaces are intended to provide abstractions to enable the "business logic" to
+ * be isolated from the actual Web Server implementation choice, so for example a concrete HttpTransaction implementation
+ * could be created by wrapping a com.sun.net.httpserver.HttpExchange, but equally another implementation could wrap
+ * javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse so for example an HttpServlet
+ * could delegate to a Server instance passing the HttpTransaction it constructed from the HttpServletRequest and
+ * HttpServletResponse.
+ *
+ * @author Fraser Adams
+ */
+public interface HttpTransaction
+{
+ /**
+ * Log the HTTP request information (primarily for debugging purposes)
+ */
+ public void logRequest();
+
+ /**
+ * Return the content passed in the request from the client as a Stream.
+ * @return the content passed in the request from the client as a Stream.
+ */
+ public InputStream getRequestStream() throws IOException;
+
+ /**
+ * Return the content passed in the request from the client as a String.
+ * @return the content passed in the request from the client as a String.
+ */
+ public String getRequestString() throws IOException;
+
+ /**
+ * Return the content passed in the request from the client as a byte[].
+ * @return the content passed in the request from the client as a byte[].
+ */
+ public byte[] getRequest() throws IOException;
+
+ /**
+ * Send the content passed as a String as an HTTP response back to the client.
+ * @param status the HTTP status code e.g. 200 for OK.
+ * @param mimeType the mimeType of the response content e.g. text/plain, text/xml, image/jpeg etc.
+ * @param content the content of the response passed as a String.
+ */
+ public void sendResponse(final int status, final String mimeType, final String content) throws IOException;
+
+ /**
+ * Send the content passed as a byte[] as an HTTP response back to the client.
+ * @param status the HTTP status code e.g. 200 for OK.
+ * @param mimeType the mimeType of the response content e.g. text/plain, text/xml, image/jpeg etc.
+ * @param content the content of the response passed as a byte[].
+ */
+ public void sendResponse(final int status, final String mimeType, final byte[] content) throws IOException;
+
+ /**
+ * Send the content passed as an InputStream as an HTTP response back to the client.
+ * @param status the HTTP status code e.g. 200 for OK.
+ * @param mimeType the mimeType of the response content e.g. text/plain, text/xml, image/jpeg etc.
+ * @param is the content of the response passed as an InputStream.
+ */
+ public void sendResponse(final int status, final String mimeType, final InputStream is) throws IOException;
+
+ /**
+ * Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
+ * @return the Internet Protocol (IP) address of the client or last proxy that sent the request.
+ */
+ public String getRemoteAddr();
+
+ /**
+ * Returns the fully qualified name of the client or the last proxy that sent the request.
+ * @return the fully qualified name of the client or the last proxy that sent the request.
+ */
+ public String getRemoteHost();
+
+ /**
+ * Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
+ * @return the Internet Protocol (IP) source port of the client or last proxy that sent the request.
+ */
+ public int getRemotePort();
+
+ /**
+ * Returns a String containing the name of the current authenticated user. If the user has not been authenticated,
+ * the method returns null.
+ * @return a String containing the name of the user making this request; null if the user has not been authenticated.
+ */
+ public String getPrincipal();
+
+ /**
+ * Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
+ * @return a String specifying the name of the method with which this request was made.
+ */
+ public String getMethod();
+
+ /**
+ * Returns the part of this request's URL from the protocol name up to the query string in the first line of
+ * the HTTP request.
+ * @return a String containing the part of the URL from the protocol name up to the query string.
+ */
+ public String getRequestURI();
+
+ /**
+ * Sets a response header with the given name and value. If the header had already been set, the new value
+ * overwrites the previous one.
+ * @param name a String specifying the header name.
+ * @param value a String specifying the header value. If it contains octet string, it should be encoded according
+ * to RFC 2047.
+ */
+ public void setHeader(final String name, final String value);
+
+ /**
+ * Returns the value of the specified request header as a String. If the request did not include a header of the
+ * specified name, this method returns null. If there are multiple headers with the same name, this method returns
+ * the first head in the request. The header name is case insensitive. You can use this method with any request
+ * header.
+ * @param name a String specifying the header name.
+ * @return a String containing the value of the requested header, or null if the request does not have a header of
+ * that name.
+ */
+ public String getHeader(final String name);
+
+ /**
+ * Returns the String value of the specified cookie.
+ * @param name a String specifying the cookie name.
+ */
+ public String getCookie(final String name);
+
+ /**
+ * Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.
+ * @param name a String specifying the cookie name.
+ * @param value a String specifying the cookie value.
+ */
+ public void addCookie(final String name, final String value);
+}
+
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSON.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSON.java
new file mode 100644
index 0000000000..dfc1e0c85d
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSON.java
@@ -0,0 +1,265 @@
+/*
+ *
+ * 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.restapi;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+// QMF2 imports
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfDescribed;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+
+/**
+ * This class provides a number of convenience methods to serialise and deserialise JSON strings to/from Java
+ * Collections or QmfData objects.
+ *
+ * The JSONMapParser class used here is largely a direct copy of org.apache.qpid.messaging.util.AddressParser
+ * as it provides a handy mechanism to parse a JSON String into a Map which is the only JSON requirement that
+ * we really need for QMF. Originally this code simply did "import org.apache.qpid.messaging.util.AddressParser;"
+ * but there's a restriction/bug on the core AddressParser whereby it serialises integers into Java Integer
+ * which means that long integer values aren't correctly stored. It's this restriction that gives Java Address
+ * Strings a defacto 2GB queue size. I should really provide a patch for the *real* AddressParser but it's better
+ * to add features covering "shorthand" forms for large values (e.g. k/K, m/M, g/G for kilo, mega, giga etc.)
+ * to both the Java and C++ AddressParser to ensure maximum consistency.
+ *
+ * Because the JSON requirements for the REST API are relatively modest a fairly simple serialisation/deserialisation
+ * mechanism is included here and in the modified AddressParser classes rather than incorporating a full-blown
+ * Java JSON parser. This helps avoid a bot of bloat and keeps dependencies limited to the core qpid classes.
+ *
+ * @author Fraser Adams
+ */
+public final class JSON
+{
+ /**
+ * Serialise an Object to JSON. Note this isn't a full JSON serialisation of java.lang.Object, rather it only
+ * includes types that are relevant to QmfData Objects and the types that may be contained therein.
+ * @param item the Object that we wish to serialise to JSON.
+ * @return the JSON String encoding.
+ */
+ public final static String fromObject(final Object item)
+ {
+ if (item == null)
+ {
+ return "";
+ }
+ else
+ {
+ if (item instanceof Map)
+ { // Check if the value part is an ObjectId and serialise appropriately
+ Map map = (Map)item;
+ if (map.containsKey("_object_name"))
+ { // Serialise "ref" properties as String versions of ObjectId to match encoding used in fromQmfData()
+ return "\"" + new ObjectId(map) + "\"";
+ }
+ else
+ {
+ return fromMap(map);
+ }
+ }
+ else if (item instanceof List)
+ {
+ return fromList((List)item);
+ }
+ else if (item instanceof QmfData)
+ {
+ return fromQmfData((QmfData)item);
+ }
+ else if (item instanceof WorkItem)
+ {
+ return fromWorkItem((WorkItem)item);
+ }
+ else if (item instanceof String)
+ {
+ return "\"" + item + "\"";
+ }
+ else if (item instanceof byte[])
+ {
+ return "\"" + new String((byte[])item) + "\"";
+ }
+ else if (item instanceof UUID)
+ {
+ return "\"" + item.toString() + "\"";
+ }
+ else
+ {
+ return item.toString();
+ }
+ }
+ }
+
+ /**
+ * Encode the Map contents so we can use the same code for fromMap and fromQmfData as the latter also needs
+ * to encode _object_id and _schema_id. This returns a String that needs to be topped and tailed with braces.
+ * @param m the Map that we wish to serialise to JSON.
+ * @return the String encoding of the contents.
+ */
+ @SuppressWarnings("unchecked")
+ private final static String encodeMapContents(final Map m)
+ {
+ Map<String, Object> map = (Map<String, Object>)m;
+ StringBuilder buffer = new StringBuilder(512);
+ int size = map.size();
+ int count = 1;
+ for (Map.Entry<String, Object> entry : map.entrySet())
+ {
+ String key = (String)entry.getKey();
+ buffer.append("\"" + key + "\":");
+
+ Object value = entry.getValue();
+ buffer.append(fromObject(value));
+ if (count++ < size)
+ {
+ buffer.append(",");
+ }
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Serialise a Map to JSON.
+ * @param m the Map that we wish to serialise to JSON.
+ * @return the JSON String encoding.
+ */
+ @SuppressWarnings("unchecked")
+ public final static String fromMap(final Map m)
+ {
+ return "{" + encodeMapContents(m) + "}";
+ }
+
+ /**
+ * Serialise a List to JSON.
+ * @param list the List that we wish to serialise to JSON.
+ * @return the JSON String encoding.
+ */
+ public final static String fromList(final List list)
+ {
+ StringBuilder buffer = new StringBuilder(512);
+ buffer.append("[");
+ int size = list.size();
+ int count = 1;
+ for (Object item : list)
+ {
+ buffer.append(fromObject(item));
+ if (count++ < size)
+ {
+ buffer.append(",");
+ }
+ }
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ /**
+ * Serialise a QmfData Object to JSON. If the Object is a QmfConsoleData we serialise the ObjectId as a String
+ * which is the same encoding used for the various "ref" properies in fromObject().
+ * @param data the QmfData that we wish to serialise to JSON.
+ * @return the JSON String encoding.
+ */
+ public final static String fromQmfData(final QmfData data)
+ {
+ String consoleDataInfo = "";
+
+ if (data instanceof QmfConsoleData)
+ {
+ QmfConsoleData consoleData = (QmfConsoleData)data;
+ SchemaClassId sid = consoleData.getSchemaClassId();
+ long[] ts = consoleData.getTimestamps();
+
+ String objectId = "\"_object_id\":\"" + consoleData.getObjectId().toString() + "\",";
+ String schemaId = "\"_schema_id\":{" +
+ "\"_package_name\":\"" + sid.getPackageName() +
+ "\",\"_class_name\":\"" + sid.getClassName() +
+ "\",\"_type\":\"" + sid.getType() +
+ "\",\"_hash\":\"" + sid.getHashString() +
+ "\"},";
+
+ String timestamps = "\"_update_ts\":" + ts[0] + "," +
+ "\"_create_ts\":" + ts[1] + "," +
+ "\"_delete_ts\":" + ts[2] + ",";
+
+ consoleDataInfo = objectId + schemaId + timestamps;
+ }
+
+ return "{" + consoleDataInfo + encodeMapContents(data.mapEncode()) + "}";
+ }
+
+ /**
+ * Serialise a WorkItem Object to JSON.
+ * @param data the WorkItem that we wish to serialise to JSON.
+ * @return the JSON String encoding.
+ */
+ public final static String fromWorkItem(final WorkItem data)
+ {
+ // TODO There are a couple of WorkItem types that won't serialise correctly - SubscriptionIndicationWorkItem
+ // and MethodCallWorkItem. Their params require a custom serialiser - though they probably won't be used
+ // from a REST API so they've been parked for now.
+ String type = "\"_type\":\"" + data.getType() + "\",";
+ Handle handle = data.getHandle();
+ String handleString = handle == null ? "" : "\"_handle\":\"" + handle.getCorrelationId() + "\",";
+ String params = "\"_params\":" + fromObject(data.getParams());
+
+ return "{" + type + handleString + params + "}";
+ }
+
+ /**
+ * Create a Map from a JSON String.
+ * The JSONMapParser class used here is largely a direct copy of org.apache.qpid.messaging.util.AddressParser
+ * as it provides a handy mechanism to parse a JSON String into a Map which is the only JSON requirement that
+ * we really need for QMF. Originally this code simply did "import org.apache.qpid.messaging.util.AddressParser;"
+ * but there's a restriction/bug on the core AddressParser whereby it serialises integers into Java Integer
+ * which means that long integer values aren't correctly stored. It's this restriction that gives Java Address
+ * Strings a defacto 2GB queue size. I should really provide a patch for the *real* AddressParser but it's better
+ * to add features covering "shorthand" forms for large values (e.g. k/K, m/M, g/G for kilo, mega, giga etc.)
+ * to both the Java and C++ AddressParser to ensure maximum consistency.
+ * @param json the JSON String that we wish to decode into a Map.
+ * @return the Map encoding of the JSON String.
+ */
+ public final static Map toMap(final String json)
+ {
+ if (json == null || json.equals(""))
+ {
+ return Collections.EMPTY_MAP;
+ }
+ else
+ {
+ return new JSONMapParser(json).map();
+ }
+ }
+
+ /**
+ * Create a QmfData from a JSON String.
+ * @param json the JSON String that we wish to decode into a QmfData.
+ * @return the QmfData encoding of the JSON String.
+ */
+ public final static QmfData toQmfData(final String json)
+ {
+ return new QmfData(toMap(json));
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSONMapParser.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSONMapParser.java
new file mode 100644
index 0000000000..9a6354e099
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/JSONMapParser.java
@@ -0,0 +1,402 @@
+/*
+ *
+ * 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.restapi;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.messaging.Address;
+import org.apache.qpid.messaging.util.Lexer;
+import org.apache.qpid.messaging.util.Lexicon;
+import org.apache.qpid.messaging.util.ParseError;
+import org.apache.qpid.messaging.util.Token;
+
+/**
+ * AddressParser
+ *
+ * This JSONMapParser class used is mostly just a direct copy of org.apache.qpid.messaging.util.AddressParser
+ * as it provides a handy mechanism to parse a JSON String into a Map which is the only JSON requirement that
+ * we really need for QMF.
+ *
+ * Unfortunately there's a restriction/bug on the core AddressParser whereby it serialises integers into Java Integer
+ * which means that long integer values aren't correctly stored. It's this restriction that gives Java Address
+ * Strings a defacto 2GB queue size. I should really provide a patch for the *real* AddressParser but it's better
+ * to add features covering "shorthand" forms for large values (e.g. k/K, m/M, g/G for kilo, mega, giga etc.)
+ * to both the Java and C++ AddressParser to ensure maximum consistency.
+ *
+ * This AddressParser clone largely uses the classes from org.apache.qpid.messaging.util like the real AddressParser
+ * but unfortunately the Parser class was package scope rather than public, so I've done some "copy and paste reuse"
+ * to add the Parser methods into this version of AddressParser. I've also removed the bits that actually create
+ * an Address as all we need to do is to parse into a java.util.Map.
+ */
+
+public class JSONMapParser
+{
+
+ private static Lexicon lxi = new Lexicon();
+
+ private static Token.Type LBRACE = lxi.define("LBRACE", "\\{");
+ private static Token.Type RBRACE = lxi.define("RBRACE", "\\}");
+ private static Token.Type LBRACK = lxi.define("LBRACK", "\\[");
+ private static Token.Type RBRACK = lxi.define("RBRACK", "\\]");
+ private static Token.Type COLON = lxi.define("COLON", ":");
+ private static Token.Type SEMI = lxi.define("SEMI", ";");
+ private static Token.Type SLASH = lxi.define("SLASH", "/");
+ private static Token.Type COMMA = lxi.define("COMMA", ",");
+ private static Token.Type NUMBER = lxi.define("NUMBER", "[+-]?[0-9]*\\.?[0-9]+");
+ // Make test for true and false case insensitive. N.B. org.apache.qpid.messaging.util.AddressParser test is
+ // case sensitive - not sure if that's a bug/oversight in the AddressParser??
+ private static Token.Type TRUE = lxi.define("TRUE", "(?i)True");
+ private static Token.Type FALSE = lxi.define("FALSE", "(?i)False");
+ private static Token.Type ID = lxi.define("ID", "[a-zA-Z_](?:[a-zA-Z0-9_-]*[a-zA-Z0-9_])?");
+ private static Token.Type STRING = lxi.define("STRING", "\"(?:[^\\\"]|\\.)*\"|'(?:[^\\']|\\.)*'");
+ private static Token.Type ESC = lxi.define("ESC", "\\\\[^ux]|\\\\x[0-9a-fA-F][0-9a-fA-F]|\\\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]");
+ private static Token.Type SYM = lxi.define("SYM", "[.#*%@$^!+-]");
+ private static Token.Type WSPACE = lxi.define("WSPACE", "[\\s]+");
+ private static Token.Type EOF = lxi.eof("EOF");
+
+ private static Lexer LEXER = lxi.compile();
+
+/********** Copied from org.apache.qpid.messaging.util.Parser as Parser was package scope **********/
+
+ private List<Token> tokens;
+ private int idx = 0;
+
+ Token next()
+ {
+ return tokens.get(idx);
+ }
+
+ boolean matches(Token.Type ... types)
+ {
+ for (Token.Type t : types)
+ {
+ if (next().getType() == t)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ Token eat(Token.Type ... types)
+ {
+ if (types.length > 0 && !matches(types))
+ {
+ throw new ParseError(next(), types);
+ }
+ else
+ {
+ Token t = next();
+ idx += 1;
+ return t;
+ }
+ }
+
+/***************************************************************************************************/
+
+ public static List<Token> lex(String input)
+ {
+ return LEXER.lex(input);
+ }
+
+ static List<Token> wlex(String input)
+ {
+ List<Token> tokens = new ArrayList<Token>();
+ for (Token t : lex(input))
+ {
+ if (t.getType() != WSPACE)
+ {
+ tokens.add(t);
+ }
+ }
+ return tokens;
+ }
+
+ static String unquote(String st, Token tok)
+ {
+ StringBuilder result = new StringBuilder();
+ for (int i = 1; i < st.length() - 1; i++)
+ {
+ char ch = st.charAt(i);
+ if (ch == '\\')
+ {
+ char code = st.charAt(i+1);
+ switch (code)
+ {
+ case '\n':
+ break;
+ case '\\':
+ result.append('\\');
+ break;
+ case '\'':
+ result.append('\'');
+ break;
+ case '"':
+ result.append('"');
+ break;
+ case 'a':
+ result.append((char) 0x07);
+ break;
+ case 'b':
+ result.append((char) 0x08);
+ break;
+ case 'f':
+ result.append('\f');
+ break;
+ case 'n':
+ result.append('\n');
+ break;
+ case 'r':
+ result.append('\r');
+ break;
+ case 't':
+ result.append('\t');
+ break;
+ case 'u':
+ result.append(decode(st.substring(i+2, i+6)));
+ i += 4;
+ break;
+ case 'v':
+ result.append((char) 0x0b);
+ break;
+ case 'o':
+ result.append(decode(st.substring(i+2, i+4), 8));
+ i += 2;
+ break;
+ case 'x':
+ result.append(decode(st.substring(i+2, i+4)));
+ i += 2;
+ break;
+ default:
+ throw new ParseError(tok);
+ }
+ i += 1;
+ }
+ else
+ {
+ result.append(ch);
+ }
+ }
+
+ return result.toString();
+ }
+
+ static char[] decode(String hex)
+ {
+ return decode(hex, 16);
+ }
+
+ static char[] decode(String code, int radix)
+ {
+ return Character.toChars(Integer.parseInt(code, radix));
+ }
+
+ /**
+ * This method is the the main place where this class differs from org.apache.qpid.messaging.util.AddressParser.
+ * If the token type is a STRING it checks for a number (with optional floating point) ending in K, M or G
+ * and if it is of this type it creates a Long out of the float value multiplied by 1000, 1000000 or 1000000000.
+ * If the token type is a NUMBER it tries to parse into an Integer like AddressParser, but if that fails it
+ * tries to parse onto a Long which allows much larger integer values to be used.
+ */
+ static Object tok2obj(Token tok)
+ {
+ Token.Type type = tok.getType();
+ String value = tok.getValue();
+ if (type == STRING)
+ {
+ value = unquote(value, tok);
+
+ // Initial regex to check for a number (with optional floating point) ending in K, M or G
+ if (value.matches("([0-9]*\\.[0-9]+|[0-9]+)\\s*[kKmMgG]"))
+ {
+ // If it's a numeric string perform the relevant multiplication and return as a Long.
+ int length = value.length();
+ if (length > 1)
+ {
+ String end = value.substring(length - 1, length).toUpperCase();
+ String start = value.substring(0, length - 1).trim();
+
+ if (end.equals("K"))
+ {
+ return Long.valueOf((long)(Float.parseFloat(start) * 1000.0));
+ }
+ else if (end.equals("M"))
+ {
+ return Long.valueOf((long)(Float.parseFloat(start) * 1000000.0));
+ }
+ else if (end.equals("G"))
+ {
+ return Long.valueOf((long)(Float.parseFloat(start) * 1000000000.0));
+ }
+ }
+
+ return value;
+ }
+ else
+ {
+ return value;
+ }
+ }
+ else if (type == NUMBER)
+ {
+ // This block extends the original AddressParser handling of NUMBER. It first attempts to parse the String
+ // into an Integer in order to be backwards compatible with AddressParser however if this causes a
+ // NumberFormatException it then attempts to parse into a Long.
+ if (value.indexOf('.') >= 0)
+ {
+ return Double.valueOf(value);
+ }
+ else
+ {
+ try
+ {
+ return Integer.decode(value);
+ }
+ catch (NumberFormatException nfe)
+ {
+ return Long.decode(value);
+ }
+ }
+ }
+ else if (type == TRUE)
+ {
+ return true;
+ }
+ else if (type == FALSE)
+ {
+ return false;
+ }
+ else
+ {
+ return value;
+ }
+ }
+
+ public JSONMapParser(String input)
+ {
+ this.tokens = wlex(input); // Copied from org.apache.qpid.messaging.util.Parser
+ this.idx = 0; // Copied from org.apache.qpid.messaging.util.Parser
+ }
+
+ public Map<Object,Object> map()
+ {
+ eat(LBRACE);
+
+ Map<Object,Object> result = new HashMap<Object,Object>();
+ while (true)
+ {
+ if (matches(NUMBER, STRING, ID, LBRACE, LBRACK))
+ {
+ keyval(result);
+ if (matches(COMMA))
+ {
+ eat(COMMA);
+ }
+ else if (matches(RBRACE))
+ {
+ break;
+ }
+ else
+ {
+ throw new ParseError(next(), COMMA, RBRACE);
+ }
+ }
+ else if (matches(RBRACE))
+ {
+ break;
+ }
+ else
+ {
+ throw new ParseError(next(), NUMBER, STRING, ID, LBRACE, LBRACK,
+ RBRACE);
+ }
+ }
+
+ eat(RBRACE);
+ return result;
+ }
+
+ void keyval(Map<Object,Object> map)
+ {
+ Object key = value();
+ eat(COLON);
+ Object val = value();
+ map.put(key, val);
+ }
+
+ Object value()
+ {
+ if (matches(NUMBER, STRING, ID, TRUE, FALSE))
+ {
+ return tok2obj(eat());
+ }
+ else if (matches(LBRACE))
+ {
+ return map();
+ }
+ else if (matches(LBRACK))
+ {
+ return list();
+ }
+ else
+ {
+ throw new ParseError(next(), NUMBER, STRING, ID, LBRACE, LBRACK);
+ }
+ }
+
+ List<Object> list()
+ {
+ eat(LBRACK);
+
+ List<Object> result = new ArrayList<Object>();
+
+ while (true)
+ {
+ if (matches(RBRACK))
+ {
+ break;
+ }
+ else
+ {
+ result.add(value());
+ if (matches(COMMA))
+ {
+ eat(COMMA);
+ }
+ else if (matches(RBRACK))
+ {
+ break;
+ }
+ else
+ {
+ throw new ParseError(next(), COMMA, RBRACK);
+ }
+ }
+ }
+
+ eat(RBRACK);
+ return result;
+ }
+
+}
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidRestAPI.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidRestAPI.java
new file mode 100644
index 0000000000..b796c12e98
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidRestAPI.java
@@ -0,0 +1,206 @@
+/*
+ *
+ * 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.restapi;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+import java.util.List;
+
+import com.sun.net.httpserver.HttpServer;
+
+import org.apache.qpid.qmf2.util.GetOpt;
+
+import org.apache.qpid.restapi.httpserver.Authenticator;
+import org.apache.qpid.restapi.httpserver.Delegator;
+
+/**
+ * Note QpidRestAPI makes use of the Java 1.6 "Easter Egg" HttpServer and associated classes to create a simple
+ * HTTP REST interface to Qpid and QMF2 functionality.
+ * <p>
+ * Because HttpServer is in the com.sun.net.httpserver.HttpServer namespace it is technically not part of core Java
+ * and so may not be supported in all JREs, however it seems to be present in the OpenJDK Runtime Environment that is
+ * installed on many Linux variants. It is documented here <a href="http://docs.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/overview-summary.html">com.sun.net.httpserver</a>
+ * <p>
+ * The reason for choosing com.sun.net.httpserver.HttpServer is simply in order to provide a very lightweight and
+ * dependency free approach to creating an HTTP Proxy. Clearly other approaches such as full-blown Servlet containers
+ * and the like might provide a better mechanism for some environments, but HttpServer really is very simple to use.
+ * <p>
+ * If there is a desire to use Servlets rather than HttpServer it should be fairly straightforward as two interfaces
+ * have been provided (Server and HttpTransaction) that abstract the key behaviour, so for example a concrete HttpTransaction
+ * implementation could be created by wrapping a com.sun.net.httpserver.HttpExchange, but equally another implementation
+ * could wrap javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse, so for example an
+ * HttpServlet could delegate to a Server instance passing the Conversation it constructed from the HttpServletRequest
+ * and HttpServletResponse in a similar way that our Delegator implementation of HttpHandler delegates to the Servers.
+ *
+ * <pre>
+ * Usage: QpidRestAPI [options]
+ *
+ * Options:
+ * -h, --help
+ * show this help message and exit
+ * -a &lt;address&gt;, --broker-addr=&lt;address&gt;
+ * broker-addr is in the form: [username/password@]
+ * hostname | ip-address [:&lt;port&gt;] ex: localhost,
+ * 10.1.1.7:10000, broker-host:10000,
+ * guest/guest@localhost
+ * Default is the host QpidRestAPI runs on & port 5672.
+ * -i &lt;address&gt;, --addr=&lt;address&gt;
+ * the hostname of the QpidRestAPI default is the wildcard address
+ * (Bind to a specific address on a multihomed host)
+ * -p &lt;port&gt;, --port=&lt;port&gt;
+ * the port the QpidRestAPI is bound to default is 8080
+ * -b &lt;backlog&gt;, --backlog=&lt;backlog&gt;
+ * the socket backlog default is 10
+ * -w &lt;directory&gt;, --webroot=&lt;directory&gt;
+ * the directory of the QpidRestAPI Web Site default is qpid-web
+ * </pre>
+ * @author Fraser Adams
+ */
+public class QpidRestAPI
+{
+ private static final String _usage =
+ "Usage: QpidRestAPI [options]\n";
+
+ private static final String _description =
+ "Creates an HTTP REST interface to enable us to send messages to Qpid brokers and use QMF2 via HTTP.\n";
+
+ private static final String _options =
+ "Options:\n" +
+ " -h, --help show this help message and exit.\n" +
+ " -a <address>, --broker-addr=<address>\n" +
+ " broker-addr is in the form: [username/password@]\n" +
+ " hostname | ip-address [:&lt;port&gt;] e.g.\n" +
+ " localhost, 10.1.1.7:10000, broker-host:10000,\n" +
+ " guest/guest@localhost, guest/guest@broker-host:10000\n" +
+ " default is the host QpidRestAPI runs on & port 5672.\n" +
+ " -i <address>, --addr=<address>\n" +
+ " the hostname of the QpidRestAPI.\n" +
+ " default is the wildcard address.\n" +
+ " (Bind to a specific address on a multihomed host).\n" +
+ " -p <port>, --port=<port>\n" +
+ " the port the QpidRestAPI is bound to.\n" +
+ " default is 8080.\n" +
+ " -b <backlog>, --backlog=<backlog>\n" +
+ " the socket backlog.\n" +
+ " default is 10\n" +
+ " -w <directory>, --webroot=<directory>\n" +
+ " the directory of the QpidRestAPI Web Site.\n" +
+ " default is qpid-web.\n";
+
+
+ /**
+ * Construct and start an instance of QpidRestAPI. This class used a Delegator class to delegate to underlying
+ * Server instances that actually implement the business logic of the REST API.
+ *
+ * @param addr the the address the QpidRestAPI is bound to (null = default).
+ * @param port the port the QpidRestAPI is bound to.
+ * @param broker the address of the Qpid broker to connect to (null = default).
+ * @param backlog the socket backlog.
+ * @param webroot the directory of the QpidRestAPI Web Site.
+ */
+ public QpidRestAPI(final String addr, final int port, String broker, final int backlog, final String webroot)
+ throws IOException
+ {
+ final InetSocketAddress inetaddr = (addr == null) ? new InetSocketAddress(port) :
+ new InetSocketAddress(addr, port);
+ final HttpServer server = HttpServer.create(inetaddr, backlog);
+
+ broker = (broker == null) ? inetaddr.getAddress().getHostAddress() + ":5672" : broker;
+
+ Delegator fileserver = new Delegator(new FileServer(webroot + "/web", true));
+ Delegator qpidserver = new Delegator(new QpidServer(broker));
+
+ Authenticator authenticator = new Authenticator(this.getClass().getCanonicalName(), webroot + "/authentication");
+
+ server.setExecutor(Executors.newCachedThreadPool());
+ server.createContext("/", fileserver);
+ server.createContext("/ui", fileserver).setAuthenticator(authenticator);
+ server.createContext("/qpid/connection", qpidserver).setAuthenticator(authenticator);
+ server.start();
+ }
+
+ /**
+ * Runs QpidRestAPI.
+ * @param args the command line arguments.
+ */
+ public static void main(String[] args) throws IOException
+ {
+ String logLevel = System.getProperty("amqj.logging.level");
+ logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG.
+ System.setProperty("amqj.logging.level", logLevel);
+
+ String[] longOpts = {"help", "host=", "port=", "backlog=", "webroot="};
+ try
+ {
+ String addr = null;
+ int port = 8080;
+ String broker = null;
+ int backlog = 10;
+ String webroot = "qpid-web";
+
+ GetOpt getopt = new GetOpt(args, "ha:i:p:b:w:", longOpts);
+ List<String[]> optList = getopt.getOptList();
+ String[] cargs = {};
+ cargs = getopt.getEncArgs().toArray(cargs);
+
+ for (String[] opt : optList)
+ {
+ if (opt[0].equals("-h") || opt[0].equals("--help"))
+ {
+ System.out.println(_usage);
+ System.out.println(_description);
+ System.out.println(_options);
+ System.exit(1);
+ }
+ else if (opt[0].equals("-a") || opt[0].equals("--broker-addr"))
+ {
+ broker = opt[1];
+ }
+ else if (opt[0].equals("-i") || opt[0].equals("--addr"))
+ {
+ addr = opt[1];
+ }
+ else if (opt[0].equals("-p") || opt[0].equals("--port"))
+ {
+ port = Integer.parseInt(opt[1]);
+ }
+ else if (opt[0].equals("-b") || opt[0].equals("--backlog"))
+ {
+ backlog = Integer.parseInt(opt[1]);
+ }
+ else if (opt[0].equals("-w") || opt[0].equals("--webroot"))
+ {
+ webroot = opt[1];
+ }
+ }
+
+ QpidRestAPI restAPI = new QpidRestAPI(addr, port, broker, backlog, webroot);
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(_usage);
+ System.out.println(e.getMessage());
+ System.exit(1);
+ }
+ }
+}
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidServer.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidServer.java
new file mode 100644
index 0000000000..f1bdcf85bc
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/QpidServer.java
@@ -0,0 +1,654 @@
+/*
+ *
+ * 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.restapi;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Misc Imports
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
+import static java.net.HttpURLConnection.HTTP_CREATED;
+import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
+import static java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED;
+import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
+
+
+/**
+ * This class implements the REST API proper, it is an implementation of the Server interface which allows us to
+ * abstract the "business logic" from the Web Server implementation technology (HttpServer/Servlet etc.).
+ * <p>
+ * The REST API is as follows:
+ * <pre>
+ * PUT: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;
+ * HTTP body: {"url":&lt;url&gt;,"connectionOptions":&lt;connectionOptions&gt;[,"disableEvents":true;]}
+ * &lt;url&gt;: A string containing an AMQP connection URL as used in the qpid::messaging API.
+ * &lt;connectionOptions&gt;: A JSON string containing connectionOptions in the form specified in the
+ * qpid::messaging API.
+ *
+ * This method creates a Qpid Connection Object with the name &lt;name&gt; using the specified url and options.
+ *
+ * The optional disableEvents property is used to start up a QMF Connection which can only
+ * do synchronous calls such as getObjects() and can't receive Agent updates or QMF2 Events.
+ *
+ * DELETE: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;
+ *
+ * This method deletes the Qpid Connection Object with the name &lt;name&gt;.
+ *
+ * POST: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/object/&lt;ObjectId&gt;
+ * HTTP body: {"_method_name":&lt;method&gt;,"_arguments":&lt;inArgs&gt;}
+ * &lt;method&gt;: A string containing the QMF2 method name e.g. "getLogLevel", "setLogLevel", "create", "delete".
+ * &lt;inArgs&gt;: A JSON string containing the method arguments e.g. {"level":"debug+:Broker"} for setLogLevel.
+ * HTTP response: A JSON string containing the response e.g. {"level":"notice+"} for getLogLevel (may be empty).
+ *
+ * This method invokes the QMF2 method &lt;method&gt; with arguments &lt;inArgs&gt; on the object &lt;ObjectId&gt;
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection;
+ *
+ * This method retrieves (as a JSON string) the complete set of connections currently enabled on the Server.
+ * The returned JSON string represents a Map keyed by the connection name/handle. The value part is itself a
+ * Map containing the Connection URL and Connection Options used to create the Qpid Connection. e.g.
+ * {"8c5116d6-46a1-489b-93d8-fde525e0d76d":{"url":"0.0.0.0:5672","connectionOptions":{}}}
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;
+ *
+ * This method retrieves (as a JSON string) a Map containing the Connection URL and Connection Options used to
+ * create the Qpid Connection with the specified &lt;name&gt;. e.g.
+ * {"url":"0.0.0.0:5672","connectionOptions":{}}
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/objects/&lt;className&gt;
+ *
+ * This method retrieves (as a JSON string) the list of QmfConsoleData objects with the specified &lt;className&gt;
+ * using the QMF2 Console associated with the Qpid Connection Object with the name &lt;name&gt;.
+ * This is the REST equivalent of Console.getObjects(className) which searches across all packages and all Agents
+ * for the specified className.
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/objects/&lt;packageName&gt;/&lt;className&gt;
+ * !!not yet implemented!!
+ * This method retrieves (as a JSON string) the list of QmfConsoleData objects with the specified
+ * &lt;packageName&gt; and &lt;className&gt; using the QMF2 Console associated with the Qpid Connection Object
+ * with the name &lt;name&gt;.
+ * This is the REST equivalent of Console.getObjects(packageName, className) which searches across all Agents
+ * for the specified className in the package packageName.
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/object/&lt;ObjectId&gt;
+ * This method retrieves (as a JSON string) the QmfConsoleData object with the specified &lt;ObjectId&gt;
+ * using the QMF2 Console associated with the Qpid Connection Object with the name &lt;name&gt;.
+ * This is the REST implementation of getObjects(oid) it is also the equivalent of the QmfConsoleData refresh()
+ * method where an object can update its state.
+ * Note that there's a slight variance on the QMF2 API here as that returns an array/list of QmfConsoledData
+ * objects for all queries, however as the call with ObjectId will only return one or zero objects this
+ * implementation returns the single QmfConsoleData object found or a 404 Not Found response.
+ *
+ * N.B. that the ManagementAgent on the broker appears not to set the timestamp properties in the response to this
+ * call, which means that they get set to current time in the QmfConsoleData, this is OK for _update_ts but not
+ * for _create_ts and _delete_ts. Users of this call should be aware of that in their own code.
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/objects
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/classes (synonyms)
+ *
+ * This method retrieves (as a JSON string) the list of SchemaClassId for all available Schema for all Agents.
+ * This is the REST equivalent of Console.getClasses() which searches across all Agents.
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/classes/&lt;agentName&gt;
+ *
+ * This method retrieves (as a JSON string) the list of SchemaClassId for all available Schema on the
+ * Agent named &lt;agentName&gt;.
+ * This is the REST equivalent of Console.getClasses(agent) which searches across a specified Agent.
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/packages
+ *
+ * This method retrieves (as a JSON string) the list of all known Packages for all Agents.
+ * This is the REST equivalent of Console.getPackages() which searches across all Agents.
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/packages/&lt;agentName&gt;
+ *
+ * This method retrieves (as a JSON string) the list of all known Packages on the Agent named &lt;agentName&gt;.
+ * This is the REST equivalent of Console.getPackages(agent) which searches across a specified Agent.
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/agents
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/agent (synonyms)
+ *
+ * This method retrieves (as a JSON string) the list of all known Agents.
+ * This is the REST equivalent of Console.getAgents().
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/agent/&lt;agentName&gt;
+ *
+ * This method retrieves (as a JSON string) the Agent named &lt;agentName&gt;.
+ * This is the REST equivalent of Console.getAgent(agentName).
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/address
+ *
+ * This method retrieves (as a JSON string) the AMQP address this Console is listening to.
+ * This is the REST equivalent of Console.getAddress().
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/workItemCount
+ *
+ * This method retrieves (as a plain text string) the count of pending WorkItems that can be retrieved
+ * from this Console.
+ * This is the REST equivalent of Console.getWorkItemCount().
+ *
+ * GET: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/console/nextWorkItem
+ *
+ * This method retrieves (as a JSON string) the next pending work item from this Console (N.B. this method
+ * blocks until a WorkItem is available so should only be called asynchronously e.g. via AJAX).
+ * This is the REST equivalent of Console.getNextWorkitem().
+ * </pre>
+ * @author Fraser Adams
+ */
+public final class QpidServer implements Server
+{
+ private static final Logger _log = LoggerFactory.getLogger(QpidServer.class);
+
+ private ConnectionStore _connections = new ConnectionStore();
+ private String _defaultBroker = null;
+
+ public QpidServer(final String broker)
+ {
+ _defaultBroker = broker;
+ }
+
+ /**
+ * Handle a "/qpid/connection/<connectionName>/console/objects" or
+ * "/qpid/connection/<connectionName>/console/objects/" request,
+ * in other words a request for information about an object resource specified by the remaining path.
+ * Only the GET method is valid for this resource and it is in effect the REST mapping for Console.getObjects().
+ */
+ private void sendGetObjectsResponse(final HttpTransaction tx, final Console console, final String path) throws IOException
+ {
+ String[] params = path.split("/");
+ if (params.length == 1)
+ { // With one parameter we call getObjects(className)
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getObjects(params[0])));
+ }
+ else if (params.length == 2)
+ { // With two parameters we call getObjects(packageName, className)
+ //System.out.println("params = " + params[0] + ", " + params[1]);
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getObjects(params[0], params[1])));
+ }
+ else if (params.length == 3)
+ { // TODO With three parameters we call getObjects(packageName, className, agent)
+ //System.out.println("params = " + params[0] + ", " + params[1] + ", " + params[2]);
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Too many parameters for objects GET request.");
+ } else {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Too many parameters for objects GET request.");
+ }
+ }
+
+ /**
+ * Called by the Web Server to allow a Server to handle a GET request.
+ * The HTTP GET URL structure for the REST API is specified above in the overall class documentation.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doGet(final HttpTransaction tx) throws IOException
+ {
+ String path = tx.getRequestURI();
+
+ //System.out.println();
+ //System.out.println("QpidServer doGet " + path);
+ //tx.logRequest();
+
+ if (path.startsWith("/qpid/connection/"))
+ {
+ path = path.substring(17);
+
+ String user = tx.getPrincipal(); // Using the principal lets different users use the default connection.
+ if (path.length() == 0)
+ { // handle "/qpid/connection/" request with unspecified connection (returns list of available connections).
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(_connections.getAll(user)));
+ }
+ else
+ { // if path.length() > 0 we're dealing with a specified Connection so extract the name and look it up.
+ String connectionName = path;
+ int i = path.indexOf("/");
+ if (i > 0) // Can use > rather than >= as we've already tested for "/qpid/connection/" above.
+ {
+ connectionName = path.substring(0, i);
+ path = path.substring(i + 1);
+ }
+ else
+ {
+ path = "";
+ }
+
+ connectionName = user + "." + connectionName;
+
+ // TODO what if we don't want a default connection.
+ // If necessary we create a new "default" Connection associated with the user. The default connection
+ // attempts to connect to a broker specified in the QpidRestAPI config (or default 0.0.0.0:5672).
+ if (connectionName.equals(user + ".default"))
+ {
+ ConnectionProxy defaultConnection = _connections.get(connectionName);
+ if (defaultConnection == null)
+ {
+ defaultConnection = _connections.create(connectionName, _defaultBroker, "", false);
+
+ // Wait a maximum of 1000ms for the underlying Qpid Connection to become available. If we
+ // don't do this the first call using the default will return 404 Not Found.
+ defaultConnection.waitForConnection(1000);
+ }
+ }
+
+ // Find the Connection with the name extracted from the URI.
+ ConnectionProxy connection = _connections.get(connectionName);
+
+ if (connection == null)
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ else if (!connection.isConnected())
+ {
+ tx.sendResponse(HTTP_INTERNAL_ERROR, "text/plain", "500 Broker Disconnected.");
+ }
+ else
+ {
+ if (path.length() == 0)
+ { // handle request for information about a specified Console
+ tx.sendResponse(HTTP_OK, "application/json", connection.toString());
+ }
+ else
+ { // In this block we are dealing with resources associated with a specified connectionName.
+ // path describes the resources specifically related to "/qpid/connection/<connectionName>"
+ Console console = connection.getConsole();
+
+ if (path.startsWith("console/objects/"))
+ { // Get information about specified objects.
+ path = path.substring(16);
+ sendGetObjectsResponse(tx, console, path);
+ }
+ else if (path.startsWith("console/objects") && path.length() == 15)
+ { // If objects is unspecified treat as a synonym for classes.
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getClasses()));
+ }
+ else if (path.startsWith("console/address/"))
+ { // Get the Console AMQP Address
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAddress()));
+ }
+ else if (path.startsWith("console/address") && path.length() == 15)
+ { // Get the Console AMQP Address
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAddress()));
+ }
+ else if (path.startsWith("console/workItemCount/"))
+ { // Returns the count of pending WorkItems that can be retrieved.
+ tx.sendResponse(HTTP_OK, "text/plain", "" + console.getWorkitemCount());
+ }
+ else if (path.startsWith("console/workItemCount") && path.length() == 21)
+ { // Returns the count of pending WorkItems that can be retrieved.
+ tx.sendResponse(HTTP_OK, "text/plain", "" + console.getWorkitemCount());
+ }
+ else if (path.startsWith("console/nextWorkItem/"))
+ { // Obtains the next pending work item, or null if none available.
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getNextWorkitem()));
+ }
+ else if (path.startsWith("console/nextWorkItem") && path.length() == 20)
+ { // Obtains the next pending work item, or null if none available.
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getNextWorkitem()));
+ }
+ else if (path.startsWith("console/agents") && path.length() == 14)
+ { // Get information about all available Agents.
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAgents()));
+ }
+ else if (path.startsWith("console/agent/"))
+ { // Get information about a specified Agent.
+ Agent agent = console.getAgent(path.substring(14));
+ if (agent == null)
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ else
+ {
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(agent));
+ }
+ }
+ else if (path.startsWith("console/agent") && path.length() == 13)
+ { // If agent is unspecified treat as a synonym for agents.
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAgents()));
+ }
+ else if (path.startsWith("console/classes/"))
+ { // Get information about the classes for a specified Agent
+ path = path.substring(16); // Get Agent name
+
+ // TODO handle getClasses() for specified Agent
+ tx.sendResponse(HTTP_NOT_IMPLEMENTED, "text/plain", "501 getClasses() for specified Agent not yet implemented.");
+ }
+ else if (path.startsWith("console/classes") && path.length() == 15)
+ { // Get information about all the classes for all Agents
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getClasses()));
+ }
+ else if (path.startsWith("console/packages/"))
+ { // Get information about the packages for a specified Agent
+ path = path.substring(17); // Get Agent name
+
+ // TODO handle getPackages() for specified Agent.
+ tx.sendResponse(HTTP_NOT_IMPLEMENTED, "text/plain", "501 getPackages() for specified Agent not yet implemented.");
+ }
+ else if (path.startsWith("object/"))
+ {
+ /**
+ * This is the REST implementation of getObjects(oid) it is also the equivalent of
+ * the QmfConsoleData refresh() method where an object can update its state.
+ * N.B. that the ManagementAgent on the broker appears not to set the timestamp properties
+ * in the response to this call, which means that they get set to current time in the
+ * QmfConsoleData, this is OK for _update_ts but not for _create_ts and _delete_ts
+ * users of this call should be aware of that in their own code.
+ */
+ path = path.substring(7);
+
+ // The ObjectId has been passed in the URI, create a real ObjectId
+ ObjectId oid = new ObjectId(path);
+
+ List<QmfConsoleData> objects = console.getObjects(oid);
+ if (objects.size() == 0)
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ else
+ {
+ // Not that in a departure from the QMF2 API this returns the QmfConsoleData object
+ // rather than a list of size one. Perhaps the APIs should be completely consistent
+ // but this response seems more convenient.
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(objects.get(0)));
+ }
+ }
+ else if (path.startsWith("console/packages") && path.length() == 16)
+ { // Get information about all the packages for all Agents
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getPackages()));
+ }
+ else
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ }
+ }
+ }
+ }
+ else if (path.startsWith("/qpid/connection"))
+ { // handle "/qpid/connection" request with unspecified connection (returns list of available connections).
+ String user = tx.getPrincipal(); // Using the principal lets different users use the default connection.
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(_connections.getAll(user)));
+ }
+ else
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ }
+
+ /**
+ * Called by the Web Server to allow a Server to handle a POST request.
+ * <pre>
+ * POST: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;/object/&lt;ObjectId&gt;
+ * HTTP body: {"_method_name":&lt;method&gt;,"_arguments":&lt;inArgs&gt;}
+ * &lt;method&gt;: A string containing the QMF2 method name e.g. "getLogLevel", "setLogLevel", "create", "delete".
+ * &lt;inArgs&gt;: A JSON string containing the method arguments e.g. {"level":"debug+:Broker"} for setLogLevel.
+ * HTTP response: A JSON string containing the response e.g. {"level":"notice+"} for getLogLevel (may be empty).
+ *
+ * This method invokes the QMF2 method &lt;method&gt; with arguments &lt;inArgs&gt; on the object &lt;ObjectId&gt;
+ * </pre>
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ @SuppressWarnings("unchecked")
+ public void doPost(final HttpTransaction tx) throws IOException
+ {
+ String path = tx.getRequestURI();
+
+ //System.out.println();
+ //System.out.println("QpidServer doPost " + path);
+ //System.out.println("thread = " + Thread.currentThread().getId());
+
+ if (path.startsWith("/qpid/connection/"))
+ {
+ path = path.substring(17);
+ String user = tx.getPrincipal();
+
+ String connectionName = path;
+ int i = path.indexOf("/");
+ if (i > 0) // Can use > rather than >= as we've already tested for "/qpid/connection/" above.
+ {
+ connectionName = user + "." + path.substring(0, i);
+ path = path.substring(i + 1);
+
+ // Find the Connection with the name extracted from the URI.
+ ConnectionProxy connection = _connections.get(connectionName);
+
+ if (connection == null)
+ {
+ _log.info("QpidServer.doPost path: {} Connection not found.", tx.getRequestURI());
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ else if (!connection.isConnected())
+ {
+ tx.sendResponse(HTTP_INTERNAL_ERROR, "text/plain", "500 Broker Disconnected.");
+ }
+ else
+ { // If we get this far we should have found a Qpid Connection so retrieve the QMF2 Console Object.
+ Console console = connection.getConsole();
+
+ if (path.startsWith("object/"))
+ {
+ path = path.substring(7);
+
+ // The ObjectId has been passed in the URI create an ObjectId and retrieve the Agent Name.
+ ObjectId oid = new ObjectId(path);
+ String agentName = oid.getAgentName();
+
+ // The qpidd ManagementAgent doesn't populate AgentName, if it's empty assume it's the broker.
+ agentName = agentName.equals("") ? "broker" : agentName;
+
+ Agent agent = console.getAgent(agentName); // Find the Agent we got the QmfData from.
+ if (agent == null)
+ {
+ _log.info("QpidServer.doPost path: {} Agent: {} not found.", tx.getRequestURI(), agentName);
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ else
+ { // If we get this far we can create the Object and invoke the method.
+ // We can create a QmfConsoleData with nothing but an ObjectId and the agent.
+ QmfConsoleData object = new QmfConsoleData(Collections.EMPTY_MAP, agent);
+ object.setObjectId(oid);
+
+ String request = tx.getRequestString();
+ _log.info("QpidServer.doPost path: {} body: {}", tx.getRequestURI(), request);
+
+ //System.out.println(request);
+ String method = "";
+ try
+ {
+ Map<String, Object> reqMap = JSON.toMap(request);
+
+ method = (String)reqMap.get("_method_name");
+ Object arguments = reqMap.get("_arguments");
+
+ Map args = (arguments instanceof Map) ? (Map)arguments : null;
+ //System.out.println("method: " + method + ", args: " + args);
+
+ // Parse the args if present into a QmfData (needed by invokeMethod).
+ QmfData inArgs = (args == null) ? new QmfData() : new QmfData(args);
+
+ // Invoke the specified method on the QmfConsoleData we've created.
+ MethodResult results = null;
+
+ _log.info("invokeMethod: {}", request);
+ results = object.invokeMethod(method, inArgs);
+ tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(results));
+ }
+ catch (QmfException qmfe)
+ {
+ _log.info("QpidServer.doPost() caught Exception {}", qmfe.getMessage());
+ tx.sendResponse(HTTP_INTERNAL_ERROR, "text/plain", "invokeMethod(" +
+ method + ") -> " + qmfe.getMessage());
+ }
+ catch (Exception e)
+ {
+ _log.info("QpidServer.doPost() caught Exception {}", e.getMessage());
+ tx.sendResponse(HTTP_INTERNAL_ERROR, "text/plain", "500 " + e.getMessage());
+ }
+ }
+ }
+ else
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ }
+ }
+ else
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ }
+ else
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ }
+
+ /**
+ * <pre>
+ * PUT: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;
+ * HTTP body: {"url":&lt;url&gt;,"connectionOptions":&lt;connectionOptions&gt;[,"disableEvents":true;]}
+ * &lt;url&gt;: A string containing an AMQP connection URL as used in the qpid::messaging API.
+ * &lt;connectionOptions&gt;: A JSON string containing connectionOptions in the form specified in the
+ * qpid::messaging API.
+ * </pre>
+ * Called by the Web Server to allow a Server to handle a PUT request.
+ * This method creates a Qpid Connection Object with the name &lt;name&gt; using the specified url and options.
+ * <p>
+ * The optional disableEvents property is used to start up a QMF Connection which can only
+ * do synchronous calls such as getObjects() and can't receive Agent updates or QMF2 Events.
+ * <p>
+ * N.B. It is possible for the Qpid broker to be unavailable when this method is called so it is actually a
+ * ConnectionProxy that is created. This method waits for up to 1000ms for the underlying Qpid Connection to
+ * become available and then returns. Clients should be aware that this method successfully returning only
+ * implies that the ConnectionProxy is in place and the underlying Qpid Connection may not be available.
+ * If the broker is down the ConnectionProxy will periodically attempt to reconnect, but whilst it is down
+ * the REST API will return a 500 Broker Disconnected response to any PUT or POST call.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ @SuppressWarnings("unchecked")
+ public void doPut(final HttpTransaction tx) throws IOException
+ {
+ String path = tx.getRequestURI();
+ //tx.logRequest();
+
+ if (path.startsWith("/qpid/connection/"))
+ {
+ path = path.substring(17);
+ String user = tx.getPrincipal();
+ String request = tx.getRequestString();
+ _log.info("QpidServer.doPut path: {} body: {}", tx.getRequestURI(), request);
+
+ String name = user + "." + path;
+
+ try
+ {
+ // The PUT request is a JSON string containing a url String property and a connectionOptions
+ // property which is itself a JSON String.
+ Map<String, String> reqMap = JSON.toMap(request);
+
+ String url = reqMap.get("url");
+ url = url.equals("") ? _defaultBroker : url;
+
+ // Extract the connectionOptions property and check its type is a MAP
+ Object options = reqMap.get("connectionOptions");
+ Map optionsMap = (options instanceof Map) ? (Map)options : null;
+
+ // Turn the connectionOptions Map back into a JSON String. Note that we can't just get
+ // connectionOptions as a String from reqMap as it is sent as JSON and the JSON.toMap()
+ // call on the POST request will fully parse it.
+ String connectionOptions = JSON.fromObject(optionsMap);
+
+ boolean disableEvents = false;
+ String disableEventsString = reqMap.get("disableEvents");
+ if (disableEventsString != null)
+ {
+ disableEvents = disableEventsString.equalsIgnoreCase("true");
+ }
+
+ ConnectionProxy proxy = _connections.create(name, url, connectionOptions, disableEvents);
+
+ // Wait a maximum of 1000ms for the underlying Qpid Connection to become available then return.
+ proxy.waitForConnection(1000);
+ tx.sendResponse(HTTP_CREATED, "text/plain", "201 Created.");
+ }
+ catch (Exception e)
+ {
+ _log.info("QpidServer.doPut() caught Exception {}", e.getMessage());
+ tx.sendResponse(HTTP_INTERNAL_ERROR, "text/plain", "500 " + e.getMessage());
+ }
+ }
+ else
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ }
+
+ /**
+ * Called by the Web Server to allow a Server to handle a DELETE request.
+ *
+ * DELETE: &lt;host&gt;:&lt;port&gt;/qpid/connection/&lt;name&gt;
+ *
+ * This method deletes the Qpid Connection Object with the name &lt;name&gt;.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doDelete(final HttpTransaction tx) throws IOException
+ {
+ String path = tx.getRequestURI();
+ //tx.logRequest();
+
+ if (path.startsWith("/qpid/connection/"))
+ {
+ path = path.substring(17);
+ String user = tx.getPrincipal();
+ String name = user + "." + path;
+
+ //System.out.println("Deleting " + name);
+ _log.info("QpidServer.doDelete path: {}", tx.getRequestURI());
+
+ _connections.delete(name);
+ tx.sendResponse(HTTP_OK, "text/plain", "200 Deleted.");
+ }
+ else
+ {
+ tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
+ }
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/Server.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/Server.java
new file mode 100644
index 0000000000..e7f5d61219
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/Server.java
@@ -0,0 +1,95 @@
+/*
+ *
+ * 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.restapi;
+
+import java.io.IOException;
+
+/**
+ * A Server represents a handler that runs within a Web server, which is invoked to process HTTP exchanges.
+ * Servers receive and respond to requests from Web clients that are encapsulated into HttpTransactions.
+ * <p>
+ * The Server and HttpTransaction interfaces are intended to provide abstractions to enable the "business logic" to
+ * be isolated from the actual Web Server implementation choice, so for example a concrete HttpTransaction implementation
+ * could be created by wrapping a com.sun.net.httpserver.HttpExchange, but equally another implementation could wrap
+ * javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse so for example an HttpServlet
+ * could delegate to a Server instance passing the HttpTransaction it constructed from the HttpServletRequest and
+ * HttpServletResponse.
+ *
+ * @author Fraser Adams
+ */
+public interface Server
+{
+ /**
+ * Called by the Web Server to allow a Server to handle a GET request.
+ * <p>
+ * The GET method should be safe, that is, without any side effects for which users are held responsible. For
+ * example, most form queries have no side effects. If a client request is intended to change stored data, the
+ * request should use some other HTTP method.
+ * <p>
+ * The GET method should also be idempotent, meaning that it can be safely repeated. Sometimes making a method safe
+ * also makes it idempotent. For example, repeating queries is both safe and idempotent, but buying a product online
+ * or modifying data is neither safe nor idempotent.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doGet(HttpTransaction tx) throws IOException;
+
+ /**
+ * Called by the Web Server to allow a Server to handle a POST request.
+ * <p>
+ * The HTTP POST method allows the client to send data of unlimited length to the Web server a single time and is
+ * useful when posting information such as credit card numbers.
+ * <p>
+ * This method does not need to be either safe or idempotent. Operations requested through POST can have side
+ * effects for which the user can be held accountable, for example, updating stored data or buying items online.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doPost(HttpTransaction tx) throws IOException;
+
+ /**
+ * Called by the Web Server to allow a Server to handle a PUT request.
+ * <p>
+ * The PUT operation allows a client to place a file on the server and is similar to sending a file by FTP.
+ * <p>
+ * This method does not need to be either safe or idempotent. Operations that doPut performs can have side effects
+ * for which the user can be held accountable. When using this method, it may be useful to save a copy of the
+ * affected URL in temporary storage.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doPut(HttpTransaction tx) throws IOException;
+
+ /**
+ * Called by the Web Server to allow a Server to handle a DELETE request.
+ * <p>
+ * The DELETE operation allows a client to remove a document or Web page from the server.
+ * <p>
+ * This method does not need to be either safe or idempotent. Operations requested through DELETE can have side
+ * effects for which users can be held accountable. When using this method, it may be useful to save a copy of the
+ * affected URL in temporary storage.
+ *
+ * @param tx the HttpTransaction containing the request from the client and used to send the response.
+ */
+ public void doDelete(HttpTransaction tx) throws IOException;
+}
+
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Authenticator.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Authenticator.java
new file mode 100644
index 0000000000..1083cb48df
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Authenticator.java
@@ -0,0 +1,151 @@
+/*
+ *
+ * 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.restapi.httpserver;
+
+// Simple Logging Facade 4 Java
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import com.sun.net.httpserver.BasicAuthenticator;
+
+/**
+ * This class implements a simple com.sun.net.httpserver.BasicAuthenticator. Clearly it's not very secure being a
+ * BasicAuthenticator that takes a plain (well Base64 encoded) username/password.
+ * TODO Clearly something more secure needs to be implemented.....
+ *
+ * This class creates a Timer used to schedule regular checks on the account.properties file and if it has changed
+ * it reloads the cache used for looking up the credentials. The poll period is every 10 seconds which should be OK
+ * for checking account updates. The class only updates the cache if the account.properties file has actually changed.
+ * Polling isn't ideal, but for this application it's probably no big deal. With Java 7 there is a Watch Service API
+ * https://blogs.oracle.com/thejavatutorials/entry/watching_a_directory_for_changes that allows asynchronous
+ * notification of changes, but it's an unnecessary dependency on Java 7 for this application.
+ *
+ * @author Fraser Adams
+ */
+public class Authenticator extends BasicAuthenticator
+{
+ private static final int CHECK_PERIOD = 10000; // Check every 10 seconds if the account properties have been changed.
+ private static final String ACCOUNT_FILENAME = "account.properties";
+ private static final Logger _log = LoggerFactory.getLogger(Authenticator.class);
+
+ private File _file;
+ private Properties _accountCache;
+ private long _accountFileLastModified = 0; // Used to check for updates to the account properties.
+
+ /**
+ * Create a Timer used to schedule regular checks on the account.properties file.
+ */
+ private Timer _timer = new Timer(true);
+
+ /**
+ * This private inner class is a fairly trivial TimerTask whose run() method simply calls checkAccountFile()
+ * in the main Authenticator class to check for account changes.
+ */
+ private final class CacheUpdater extends TimerTask
+ {
+ public void run()
+ {
+ checkAccountFile();
+ }
+ }
+
+ /**
+ * Construct the Authenticator. This fires up the CacheUpdater TimerTask to periodically check for changes.
+ * @param realm the authentication realm to use.
+ * @param path the path of the directory holding the account properties file.
+ */
+ public Authenticator(final String realm, final String path)
+ {
+ super(realm);
+
+ String accountPathname = path + "/" + ACCOUNT_FILENAME;
+ _file = new File(accountPathname);
+
+ if (_file.exists())
+ {
+ CacheUpdater updater = new CacheUpdater();
+ _timer.schedule(updater, 0, CHECK_PERIOD);
+ }
+ else
+ {
+ System.out.println("Authentication file " + accountPathname + " is missing.\nCannot continue - exiting.");
+ System.exit(1);
+ }
+ }
+
+ /**
+ * Checks if the account properties file has been updated, if it has it calls loadCache() to reload the cache.
+ */
+ public void checkAccountFile()
+ {
+ long mtime = _file.lastModified();
+ if (mtime != _accountFileLastModified)
+ {
+ _accountFileLastModified = mtime;
+ loadCache();
+ }
+ }
+
+ /**
+ * Load the account properties file into the account cache.
+ */
+ private void loadCache()
+ {
+ try
+ {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(_file));
+
+ // Set the cache to be the newly loaded one.
+ _accountCache = properties;
+ }
+ catch (IOException ex)
+ {
+ _log.info("loadCache failed with {}.", ex.getMessage());
+ }
+ }
+
+ @Override
+ public boolean checkCredentials(final String username, final String password)
+ {
+ //System.out.println("username = " + username);
+ //System.out.println("password = " + password);
+
+ // The original version of this forgot to check check for a null username Property. Thanks to
+ // Bruno Matos for picking that up and supplying the fix below.
+ if (_accountCache.getProperty(username) != null &&
+ _accountCache.getProperty(username).equals(password))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Delegator.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Delegator.java
new file mode 100644
index 0000000000..9dfd1fea0c
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/Delegator.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * 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.restapi.httpserver;
+
+import java.io.IOException;
+import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+
+import org.apache.qpid.restapi.HttpTransaction;
+import org.apache.qpid.restapi.Server;
+
+/**
+ * Delegator is an implementation of com.sun.net.httpserver.HttpHandler that is used to delegate to Server objects
+ * and thus provide an abstraction between the Web Server implementation (e.g. HttpServer or Servlets) and the
+ * implementation neutral Server and HttpTransaction interfaces.
+ * <p>
+ * In order to replace the HttpServer implementation with a Servlet based implementation all that should be necessary
+ * is a concrete implementation of HttpTransaction that wraps HttpServletRequest and HttpServletResponse and subclasses
+ * of HttpServlet that delegate to the appropriate Server instances from the appropriate context in a similar way
+ * to the Delegator class here.
+ *
+ * @author Fraser Adams
+ */
+public class Delegator implements HttpHandler
+{
+ private final Server _server;
+
+ /**
+ * Construct a Delegator instance that delegates to the specified Server instance.
+ * @param server the Server instance that this Delegator delegates to.
+ */
+ public Delegator(Server server)
+ {
+ _server = server;
+ }
+
+ /**
+ * Implements the HttpHandler handle interface and delegates to the Server instance.
+ * @param exchange the HttpExchange exchange object passed by the HttpServer. This will be used to construct
+ * an HttpTransaction instance that will be passed to the Server.
+ */
+ public void handle(final HttpExchange exchange) throws IOException
+ {
+ HttpTransaction tx = new HttpExchangeTransaction(exchange);
+ String method = tx.getMethod();
+ if (method.equals("GET"))
+ {
+ _server.doGet(tx);
+ }
+ else if (method.equals("POST"))
+ {
+ _server.doPost(tx);
+ }
+ else if (method.equals("PUT"))
+ {
+ _server.doPut(tx);
+ }
+ else if (method.equals("DELETE"))
+ {
+ _server.doDelete(tx);
+ }
+ else
+ {
+ tx.sendResponse(HTTP_BAD_METHOD, "text/plain", "405 Bad Method.");
+ }
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/HttpExchangeTransaction.java b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/HttpExchangeTransaction.java
new file mode 100644
index 0000000000..78932ec399
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/httpserver/HttpExchangeTransaction.java
@@ -0,0 +1,311 @@
+/*
+ *
+ * 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.restapi.httpserver;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
+
+import com.sun.net.httpserver.Headers;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+
+import org.apache.qpid.restapi.HttpTransaction;
+
+/**
+ * This class provides an implementation of the HttpTransaction interface that wraps com.sun.net.httpserver.HttpExchange
+ * in order to provide an implementation neutral facade to the Server classes.
+ *
+ * @author Fraser Adams
+ */
+public final class HttpExchangeTransaction implements HttpTransaction
+{
+ final HttpExchange _exchange;
+
+ /**
+ * Construct an HttpExchangeTransaction from an HttpExchange object.
+ */
+ public HttpExchangeTransaction(final HttpExchange exchange)
+ {
+ _exchange = exchange;
+ }
+
+ /**
+ * Log the HTTP request information (primarily for debugging purposes)
+ */
+ public void logRequest()
+ {
+ System.out.println(_exchange.getRequestMethod() + " " + _exchange.getRequestURI());
+ for (Map.Entry<String, List<String>> header : _exchange.getRequestHeaders().entrySet())
+ {
+ System.out.println(header);
+ }
+ System.out.println("From: " + getRemoteHost() + ":" + getRemotePort());
+ }
+
+ /**
+ * Return the content passed in the request from the client as a Stream.
+ * @return the content passed in the request from the client as a Stream.
+ */
+ public InputStream getRequestStream() throws IOException
+ {
+ return _exchange.getRequestBody();
+ }
+
+ /**
+ * Return the content passed in the request from the client as a String.
+ * @return the content passed in the request from the client as a String.
+ */
+ public String getRequestString() throws IOException
+ {
+ return new String(getRequest());
+ }
+
+
+ /**
+ * Return the content passed in the request from the client as a byte[].
+ * @return the content passed in the request from the client as a byte[].
+ */
+ public byte[] getRequest() throws IOException
+ {
+ InputStream is = _exchange.getRequestBody();
+
+ // Convert InputStream to byte[].
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int len;
+ while ((len = is.read(buffer, 0, 1024)) != -1)
+ {
+ bos.write(buffer, 0, len);
+ }
+ return bos.toByteArray();
+ }
+
+ /**
+ * Send the content passed as a String as an HTTP response back to the client.
+ * @param status the HTTP status code e.g. 200 for OK.
+ * @param mimeType the mimeType of the response content e.g. text/plain, text/xml, image/jpeg etc.
+ * @param content the content of the response passed as a String.
+ */
+ public void sendResponse(final int status, final String mimeType, final String content) throws IOException
+ {
+ if (content == null)
+ { // If response length has the value -1 then no response body is being sent.
+ _exchange.getResponseHeaders().set("Content-Type", mimeType);
+ _exchange.sendResponseHeaders(status, -1);
+ _exchange.close();
+ }
+ else
+ {
+ sendResponse(status, mimeType, content.getBytes());
+ }
+ }
+
+ /**
+ * Send the content passed as a byte[] as an HTTP response back to the client.
+ * @param status the HTTP status code e.g. 200 for OK.
+ * @param mimeType the mimeType of the response content e.g. text/plain, text/xml, image/jpeg etc.
+ * @param content the content of the response passed as a byte[].
+ */
+ public void sendResponse(final int status, final String mimeType, final byte[] content) throws IOException
+ {
+ _exchange.getResponseHeaders().set("Content-Type", mimeType);
+ if (content == null)
+ { // If response length has the value -1 then no response body is being sent.
+ _exchange.sendResponseHeaders(status, -1);
+ _exchange.close();
+ }
+ else
+ {
+ _exchange.sendResponseHeaders(status, content.length);
+ OutputStream os = _exchange.getResponseBody();
+ os.write(content);
+ os.flush();
+ os.close();
+ _exchange.close();
+ }
+ }
+
+ /**
+ * Send the content passed as an InputStream as an HTTP response back to the client.
+ * @param status the HTTP status code e.g. 200 for OK.
+ * @param mimeType the mimeType of the response content e.g. text/plain, text/xml, image/jpeg etc.
+ * @param is the content of the response passed as an InputStream.
+ */
+ public void sendResponse(final int status, final String mimeType, final InputStream is) throws IOException
+ {
+ _exchange.getResponseHeaders().set("Content-Type", mimeType);
+ if (is == null)
+ { // If response length has the value -1 then no response body is being sent.
+ _exchange.sendResponseHeaders(status, -1);
+ _exchange.close();
+ }
+ else
+ {
+ _exchange.sendResponseHeaders(status, 0); // For a stream we set to zero to force chunked transfer encoding.
+ OutputStream os = _exchange.getResponseBody();
+
+ byte[] buffer = new byte[8192];
+ while (true)
+ {
+ int read = is.read(buffer, 0, buffer.length);
+ if (read == -1) // Loop until EOF is reached
+ {
+ break;
+ }
+ os.write(buffer, 0, read);
+ }
+
+ os.flush();
+ os.close();
+ _exchange.close();
+ }
+ }
+
+ /**
+ * Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
+ * @return the Internet Protocol (IP) address of the client or last proxy that sent the request.
+ */
+ public String getRemoteAddr()
+ {
+ return _exchange.getRemoteAddress().getAddress().getHostAddress();
+ }
+
+ /**
+ * Returns the fully qualified name of the client or the last proxy that sent the request.
+ * @return the fully qualified name of the client or the last proxy that sent the request.
+ */
+ public String getRemoteHost()
+ {
+ return _exchange.getRemoteAddress().getHostName();
+ }
+
+ /**
+ * Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.
+ * @return the Internet Protocol (IP) source port of the client or last proxy that sent the request.
+ */
+ public int getRemotePort()
+ {
+ return _exchange.getRemoteAddress().getPort();
+ }
+
+ /**
+ * Returns a String containing the name of the current authenticated user. If the user has not been authenticated,
+ * the method returns null.
+ * @return a String containing the name of the user making this request; null if the user has not been authenticated.
+ */
+ public String getPrincipal()
+ {
+ HttpPrincipal principal = _exchange.getPrincipal();
+ return principal == null ? null : principal.getUsername();
+ }
+
+ /**
+ * Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
+ * @return a String specifying the name of the method with which this request was made.
+ */
+ public String getMethod()
+ {
+ return _exchange.getRequestMethod();
+ }
+
+ /**
+ * Returns the part of this request's URL from the protocol name up to the query string in the first line of
+ * the HTTP request.
+ * @return a String containing the part of the URL from the protocol name up to the query string.
+ */
+ public String getRequestURI()
+ {
+ return _exchange.getRequestURI().getPath();
+ }
+
+ /**
+ * Sets a response header with the given name and value. If the header had already been set, the new value
+ * overwrites the previous one.
+ * @param name a String specifying the header name.
+ * @param value a String specifying the header value. If it contains octet string, it should be encoded according
+ * to RFC 2047.
+ */
+ public void setHeader(final String name, final String value)
+ {
+ _exchange.getResponseHeaders().set(name, value);
+ }
+
+ /**
+ * Returns the value of the specified request header as a String. If the request did not include a header of the
+ * specified name, this method returns null. If there are multiple headers with the same name, this method returns
+ * the first head in the request. The header name is case insensitive. You can use this method with any request
+ * header.
+ * @param name a String specifying the header name.
+ * @return a String containing the value of the requested header, or null if the request does not have a header of
+ * that name.
+ */
+ public String getHeader(final String name)
+ {
+ return _exchange.getRequestHeaders().getFirst(name);
+ }
+
+ /**
+ * Returns the String value of the specified cookie.
+ * @param name a String specifying the cookie name.
+ */
+ public String getCookie(final String name)
+ {
+ Headers headers = _exchange.getRequestHeaders();
+ if (!headers.containsKey("Cookie"))
+ {
+ return null;
+ }
+
+ List<String> values = headers.get("cookie");
+ for (String value : values)
+ {
+ String[] cookies = value.split(";");
+ for (String cookie : cookies)
+ {
+ String[] cdata = cookie.split("=");
+ if (cdata[0].trim().equals(name))
+ {
+ //return URLDecode(cdata[1]);
+ return cdata[1];
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.
+ * @param name a String specifying the cookie name.
+ * @param value a String specifying the cookie value.
+ */
+ public void addCookie(final String name, final String value)
+ {
+ //String data = name + "=" + URLEncode(value) + "; path=/";
+ String data = name + "=" + value + "; path=/";
+ _exchange.getResponseHeaders().add("Set-Cookie", data);
+ }
+}
+
+
diff --git a/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/servlet/TODO b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/servlet/TODO
new file mode 100644
index 0000000000..1c3eabcbb1
--- /dev/null
+++ b/qpid/tools/src/java/src/restapi/java/org/apache/qpid/restapi/servlet/TODO
@@ -0,0 +1,4 @@
+The org.apache.qpid.restapi.HttpTransaction and org.apache.qpid.restapi.Server interfaces are intended to
+provide abstractions to the underlying HTTP Server technology and thus should make it fairly easy to do
+a Servlet based implementation without having to rewrite the core REST API code. A Servlet implementation
+is still on the "TODO" list though.
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java
new file mode 100644
index 0000000000..3094ba406f
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentExternalTest.java
@@ -0,0 +1,558 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.AgentExternal;
+import org.apache.qpid.qmf2.agent.MethodCallParams;
+import org.apache.qpid.qmf2.agent.MethodCallWorkItem;
+import org.apache.qpid.qmf2.agent.ResubscribeParams;
+import org.apache.qpid.qmf2.agent.ResubscribeRequestWorkItem;
+import org.apache.qpid.qmf2.agent.SubscribeRequestWorkItem;
+import org.apache.qpid.qmf2.agent.SubscribableAgent;
+import org.apache.qpid.qmf2.agent.Subscription;
+import org.apache.qpid.qmf2.agent.SubscriptionParams;
+import org.apache.qpid.qmf2.agent.UnsubscribeRequestWorkItem;
+import org.apache.qpid.qmf2.agent.QueryWorkItem;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.Handle;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * Class used to test the AgentExternal.
+ * This class provides a demo of all of the features available on the AgentExternal model including Subscriptions.
+ * It provides essentially the same behaviour as the AgentTest class though requires a lot more code.
+ *
+ * The AgentExternal class and this demo are largely provided for completeness (although they do behave correctly)
+ * as the author isn't convinced that there's a good reason for using AgentExternal rather than Agent.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentExternalTest implements QmfEventListener, SubscribableAgent
+{
+ /**
+ * This TimerTask causes the Agent to Reap any objects marked as deleted when it gets scheduled
+ */
+ private final class Reaper extends TimerTask
+ {
+ public void run()
+ {
+ // Reap any QmfAgentData Objects that have been marked as Deleted
+ // Use the iterator approach rather than foreach as we may want to call iterator.remove() to zap an entry
+ Iterator<QmfAgentData> i = _objectIndex.values().iterator();
+ while (i.hasNext())
+ {
+ QmfAgentData object = i.next();
+ if (object.isDeleted())
+ {
+System.out.println("****** Removing deleted Object *******");
+ i.remove();
+ }
+ }
+ }
+ }
+
+ private AgentExternal _agent;
+ private QmfAgentData _control;
+ private SchemaObjectClass _exceptionSchema;
+ private SchemaObjectClass _controlSchema;
+ private SchemaObjectClass _childSchema;
+ private SchemaEventClass _eventSchema;
+
+ /**
+ * objectIndex is the global index of QmfAgentData objects registered with this Agent
+ */
+ private Map<ObjectId, QmfAgentData> _objectIndex = new ConcurrentHashMap<ObjectId, QmfAgentData>();
+
+ /**
+ * This Map is used to look up Subscriptions by SubscriptionId
+ */
+ private Map<String, Subscription> _subscriptions = new ConcurrentHashMap<String, Subscription>();
+
+ private Timer _timer;
+
+ public AgentExternalTest(String url)
+ {
+ try
+ {
+ System.out.println("** Starting AgentExternalTest a test of basic AgentExternal class functions **");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _agent = new AgentExternal(this);
+ _agent.setVendor("profitron.com");
+ _agent.setProduct("gizmo");
+ _agent.setValue("attr1", 2000);
+
+ System.out.println("Agent name: " + _agent.getName());
+
+ // Schedule a Reap every 10 seconds sending the first one immediately
+ _timer = new Timer(true);
+ _timer.schedule(new Reaper(), 0, 10000);
+
+ setupSchema();
+ populateData();
+
+ _agent.setConnection(connection);
+
+ for (int i = 0; i < 100; i++)
+ {
+ _control.setValue("offset", i);
+ //control.update(); // Send data indication to the Subscriber on the next Subscription interval
+ _control.publish(); // Send data indication to the Subscriber immediately
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+
+ _control.destroy();
+
+
+ // A getObjects call seems necessary to enable automatic reconnection when broker restarts
+ // I've got no idea why this is the case though!!!
+ //List<QmfConsoleData> connections = console.getObjects("broker");
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentExternalTest failed");
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ System.out.println("WorkItem type: " + wi.getType());
+
+ if (wi.getType() == METHOD_CALL)
+ {
+ _control.incValue("methodCount", 1);
+
+ MethodCallWorkItem item = (MethodCallWorkItem)wi;
+ MethodCallParams methodCallParams = item.getMethodCallParams();
+ String methodName = methodCallParams.getName();
+ ObjectId objectId = methodCallParams.getObjectId();
+ String userId = methodCallParams.getUserId();
+ QmfData inArgs = methodCallParams.getArgs();
+ ObjectId controlAddress = _control.getObjectId();
+
+ System.out.println("Method Call User ID = " + userId);
+
+ try
+ {
+ if (objectId == null)
+ {
+ // Method invoked directly on Agent
+ if (methodName.equals("toString"))
+ {
+ QmfData outArgs = new QmfData();
+ outArgs.setValue("string", _agent.toString());
+ _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+ }
+ }
+ else if (objectId.equals(controlAddress))
+ {
+ if (methodName.equals("stop"))
+ {
+ System.out.println("Invoked stop method");
+ String message = inArgs.getStringValue("message");
+ System.out.println("Stopping: message = " + message);
+ _agent.methodResponse(methodName, item.getHandle(), null, null);
+ _agent.destroy();
+ System.exit(1);
+ }
+ else if (methodName.equals("echo"))
+ {
+ System.out.println("Invoked echo method");
+ _agent.methodResponse(methodName, item.getHandle(), inArgs, null);
+ }
+ else if (methodName.equals("event"))
+ {
+ System.out.println("Invoked event method");
+ QmfEvent event = new QmfEvent(_eventSchema);
+ event.setSeverity((int)inArgs.getLongValue("severity"));
+ event.setValue("text", inArgs.getStringValue("text"));
+ _agent.raiseEvent(event);
+ _agent.methodResponse(methodName, item.getHandle(), null, null);
+ }
+ else if (methodName.equals("fail"))
+ {
+ System.out.println("Invoked fail method");
+ QmfData error = new QmfData();
+ if (inArgs.getBooleanValue("useString"))
+ {
+ error.setValue("error_text", inArgs.getStringValue("stringVal"));
+ }
+ else
+ {
+ error.setValue("whatHappened", "It Failed");
+ error.setValue("howBad", 75);
+ error.setValue("details", inArgs.getValue("details"));
+ }
+ _agent.methodResponse(methodName, item.getHandle(), null, error);
+ }
+ else if (methodName.equals("create_child"))
+ {
+ System.out.println("Invoked create_child method");
+ String childName = inArgs.getStringValue("name");
+ System.out.println("childName = " + childName);
+ QmfAgentData child = new QmfAgentData(_childSchema);
+ child.setValue("name", childName);
+ addObject(child);
+ QmfData outArgs = new QmfData();
+ outArgs.setRefValue("childAddr", child.getObjectId(), "reference"); // Set suptype just to test
+ _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+ }
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentExternalTest failed");
+ QmfData error = new QmfData();
+ error.setValue("error_text", qmfe.getMessage());
+ _agent.methodResponse(methodName, item.getHandle(), null, error);
+ }
+ }
+
+ if (wi.getType() == QUERY)
+ {
+ QueryWorkItem item = (QueryWorkItem)wi;
+ QmfQuery query = item.getQmfQuery();
+
+ System.out.println("Query User ID = " + item.getUserId());
+
+ if (query.getObjectId() != null)
+ {
+ // Look up a QmfAgentData object by the ObjectId obtained from the query
+ ObjectId objectId = query.getObjectId();
+ QmfAgentData object = _objectIndex.get(objectId);
+ if (object != null && !object.isDeleted())
+ {
+ _agent.queryResponse(item.getHandle(), object);
+ }
+ _agent.queryComplete(item.getHandle(), 0);
+ }
+ else
+ {
+ // Look up QmfAgentData objects by the SchemaClassId obtained from the query
+ // This is implemented by a linear search and allows searches with only the className specified.
+ // Linear searches clearly don't scale brilliantly, but the number of QmfAgentData objects managed
+ // by an Agent is generally fairly small, so it should be OK. Note that this is the same approach
+ // taken by the C++ broker ManagementAgent, so if it's a problem here........
+ for (QmfAgentData object : _objectIndex.values())
+ {
+ if (!object.isDeleted() && query.evaluate(object))
+ {
+ _agent.queryResponse(item.getHandle(), object);
+ }
+ }
+ _agent.queryComplete(item.getHandle(), 0);
+ }
+ }
+
+ if (wi.getType() == SUBSCRIBE_REQUEST)
+ {
+ SubscribeRequestWorkItem item = (SubscribeRequestWorkItem)wi;
+ SubscriptionParams params = item.getSubscriptionParams();
+ Handle handle = item.getHandle();
+
+ System.out.println("Subscribe Request User ID = " + params.getUserId());
+
+ try
+ {
+ Subscription subscription = new Subscription(this, params);
+ _subscriptions.put(subscription.getSubscriptionId(), subscription);
+ _timer.schedule(subscription, 0, params.getPublishInterval());
+
+ if (subscription == null)
+ {
+System.out.println("Requested Subscription has already expired or been cancelled");
+ QmfData error = new QmfData();
+ error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
+ _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
+ }
+ else
+ {
+ _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(),
+ subscription.getDuration(), subscription.getInterval(), null);
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ _agent.raiseException(handle, "Subscribe Request failed, invalid Query: " + qmfe.getMessage());
+ }
+ }
+
+ if (wi.getType() == RESUBSCRIBE_REQUEST)
+ {
+ ResubscribeRequestWorkItem item = (ResubscribeRequestWorkItem)wi;
+ ResubscribeParams params = item.getResubscribeParams();
+ Handle handle = item.getHandle();
+
+ System.out.println("Resubscribe Request User ID = " + params.getUserId());
+
+ String subscriptionId = params.getSubscriptionId();
+ Subscription subscription = _subscriptions.get(subscriptionId);
+ if (subscription != null)
+ {
+ subscription.refresh(params);
+ _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), subscription.getSubscriptionId(),
+ subscription.getDuration(), subscription.getInterval(), null);
+ }
+ else
+ {
+System.out.println("Requested Subscription has already expired or been cancelled");
+ QmfData error = new QmfData();
+ error.setValue("error_text", "Requested Subscription has already expired or been cancelled");
+ _agent.subscriptionResponse(handle, subscription.getConsoleHandle(), null, 0, 0, error);
+ }
+ }
+
+ if (wi.getType() == UNSUBSCRIBE_REQUEST)
+ {
+ UnsubscribeRequestWorkItem item = (UnsubscribeRequestWorkItem)wi;
+ String subscriptionId = item.getSubscriptionId();
+System.out.println("Received cancellation request for " + subscriptionId);
+ Subscription subscription = _subscriptions.get(subscriptionId);
+ if (subscription != null)
+ {
+ subscription.cancel();
+ }
+ }
+
+ }
+
+ public void setupSchema() throws QmfException
+ {
+ System.out.println("*** AgentExternalTest initialising the various Schema classes ***");
+
+ // Create and register schema for this agent.
+ String packageName = "com.profitron.gizmo";
+
+ // Declare a schema for a structured exception that can be used in failed method invocations.
+ _exceptionSchema = new SchemaObjectClass(packageName, "exception");
+ _exceptionSchema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+ _exceptionSchema.addProperty(new SchemaProperty("howBad", QmfType.TYPE_INT));
+ _exceptionSchema.addProperty(new SchemaProperty("details", QmfType.TYPE_MAP));
+
+ // Declare a control object to test methods against.
+ _controlSchema = new SchemaObjectClass(packageName, "control");
+ _controlSchema.addProperty(new SchemaProperty("state", QmfType.TYPE_STRING));
+ _controlSchema.addProperty(new SchemaProperty("methodCount", QmfType.TYPE_INT));
+ _controlSchema.addProperty(new SchemaProperty("offset", QmfType.TYPE_INT));
+ _controlSchema.setIdNames("state");
+
+ SchemaMethod stopMethod = new SchemaMethod("stop", "Stop Agent");
+ stopMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:IN}"));
+ _controlSchema.addMethod(stopMethod);
+
+ SchemaMethod echoMethod = new SchemaMethod("echo", "Echo Arguments");
+ echoMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:INOUT}"));
+ _controlSchema.addMethod(echoMethod);
+
+ SchemaMethod eventMethod = new SchemaMethod("event", "Raise an Event");
+ eventMethod.addArgument(new SchemaProperty("text", QmfType.TYPE_STRING, "{dir:IN}"));
+ eventMethod.addArgument(new SchemaProperty("severity", QmfType.TYPE_INT, "{dir:IN}"));
+ _controlSchema.addMethod(eventMethod);
+
+ SchemaMethod failMethod = new SchemaMethod("fail", "Expected to Fail");
+ failMethod.addArgument(new SchemaProperty("useString", QmfType.TYPE_BOOL, "{dir:IN}"));
+ failMethod.addArgument(new SchemaProperty("stringVal", QmfType.TYPE_STRING, "{dir:IN}"));
+ failMethod.addArgument(new SchemaProperty("details", QmfType.TYPE_MAP, "{dir:IN}"));
+ _controlSchema.addMethod(failMethod);
+
+ SchemaMethod createMethod = new SchemaMethod("create_child", "Create Child Object");
+ createMethod.addArgument(new SchemaProperty("name", QmfType.TYPE_STRING, "{dir:IN}"));
+ createMethod.addArgument(new SchemaProperty("childAddr", QmfType.TYPE_MAP, "{dir:OUT}"));
+ _controlSchema.addMethod(createMethod);
+
+ // Declare the child class
+ _childSchema = new SchemaObjectClass(packageName, "child");
+ _childSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+ _childSchema.setIdNames("name");
+
+ // Declare the event class
+ _eventSchema = new SchemaEventClass(packageName, "event");
+ _eventSchema.addProperty(new SchemaProperty("text", QmfType.TYPE_STRING));
+
+ System.out.println("AgentExternalTest Schema classes initialised OK");
+
+ _agent.registerObjectClass(_exceptionSchema);
+ _agent.registerObjectClass(_controlSchema);
+ _agent.registerObjectClass(_childSchema);
+ _agent.registerEventClass(_eventSchema);
+
+ System.out.println("AgentExternalTest Schema classes registered OK");
+ }
+
+ public void populateData() throws QmfException
+ {
+ System.out.println("*** AgentExternalTest creating a control object ***");
+
+ _control = new QmfAgentData(_controlSchema);
+ _control.setValue("state", "OPERATIONAL");
+ _control.setValue("methodCount", 0);
+
+ addObject(_control);
+ System.out.println("AgentExternalTest Schema control object added OK");
+ }
+
+ public void addObject(QmfAgentData object) throws QmfException
+ {
+ ObjectId addr = _agent.allocObjectId(UUID.randomUUID().toString());
+ object.setObjectId(addr);
+ _objectIndex.put(addr, object);
+
+ // Does the new object match any Subscriptions? If so add a reference to the matching Subscription and publish.
+ for (Subscription subscription : _subscriptions.values())
+ {
+ QmfQuery query = subscription.getQuery();
+ if (query.getObjectId() != null)
+ {
+ if (query.getObjectId().equals(addr))
+ {
+ object.addSubscription(subscription.getSubscriptionId(), subscription);
+ object.publish();
+ }
+ }
+ else if (query.evaluate(object))
+ {
+ object.addSubscription(subscription.getSubscriptionId(), subscription);
+ object.publish();
+ }
+ }
+ }
+
+
+
+ // methods implementing SubscriberProxy interface
+ // ********************************************************************************************************
+
+ /**
+ * Send a list of updated subscribed data to the Console.
+ *
+ * @param handle the console reply handle
+ * @param results a list of subscribed data in Map encoded form
+ */
+ public void sendSubscriptionIndicate(Handle handle, List<Map> results)
+ {
+ _agent.sendSubscriptionIndicate(handle, results);
+ }
+
+ /**
+ * This method evaluates a QmfQuery over the Agent's data on behalf of a Subscription
+ *
+ * @param query the QmfQuery that the Subscription wants to be evaluated over the Agent's data
+ * @return a List of QmfAgentData objects that match the specified QmfQuery
+ */
+ public List<QmfAgentData> evaluateQuery(QmfQuery query)
+ {
+ List<QmfAgentData> results = new ArrayList<QmfAgentData>(_objectIndex.size());
+ if (query.getTarget() == QmfQueryTarget.OBJECT)
+ {
+ if (query.getObjectId() != null)
+ {
+ // Look up a QmfAgentData object by the ObjectId obtained from the query
+ ObjectId objectId = query.getObjectId();
+ QmfAgentData object = _objectIndex.get(objectId);
+ if (object != null && !object.isDeleted())
+ {
+ results.add(object);
+ }
+ }
+ else
+ {
+ // Look up QmfAgentData objects evaluating the query
+ for (QmfAgentData object : _objectIndex.values())
+ {
+ if (!object.isDeleted() && query.evaluate(object))
+ {
+ results.add(object);
+ }
+ }
+ }
+ }
+ return results;
+ }
+
+ /**
+ * This method is called by the Subscription to tell the SubscriberProxy that the Subscription has been cancelled.
+ *
+ * @param subscription the Subscription that has been cancelled and is requesting removal.
+ */
+ public void removeSubscription(Subscription subscription)
+ {
+ _subscriptions.remove(subscription.getSubscriptionId());
+ }
+
+
+ public static void main(String[] args)
+ {
+ //System.out.println("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ AgentExternalTest test1 = new AgentExternalTest(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("ConnectionAudit main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending AgentExternalTest ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java
new file mode 100644
index 0000000000..3bc84e1ee9
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentSubscriptionTestConsole.java
@@ -0,0 +1,224 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.MethodResponseWorkItem;
+import org.apache.qpid.qmf2.console.ObjectUpdateWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.console.SubscribeIndication;
+import org.apache.qpid.qmf2.console.SubscribeParams;
+import org.apache.qpid.qmf2.console.SubscribeResponseWorkItem;
+import org.apache.qpid.qmf2.console.SubscriptionIndicationWorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * This class is the Console part of AgentTest which together provide a test of subscription behaviour
+ *
+ * N.B. AgentTest needs to be running for this test to behave as expected.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentSubscriptionTestConsole implements QmfEventListener
+{
+ private Console _console;
+ private Agent _gizmo;
+
+ public AgentSubscriptionTestConsole(String url)
+ {
+ try
+ {
+ System.out.println("** Starting AgentSubscriptionTestConsole used to test subscription behaviour **");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(this);
+ _console.addConnection(connection);
+
+ // Wait until the gizmo Agent has been discovered
+ _gizmo = _console.findAgent("gizmo");
+ if (_gizmo == null)
+ {
+ System.out.println("gizmo Agent not found, you probably need to run AgentTest1");
+ System.exit(1);
+ }
+
+ System.out.println("Creating Query for objects whose state property has a value that starts with 'OP'");
+
+ SubscribeParams params;
+ QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, "['re_match', 'state', ['quote', '^OP']]");
+
+ // Create a subscription, response returned synchronously
+ params = _console.createSubscription(_gizmo, query, "consoleHandle1", "{publishInterval:5}");
+ System.out.println("duration = " + params.getLifetime());
+ System.out.println("interval = " + params.getPublishInterval());
+ System.out.println("subscriptionId = " + params.getSubscriptionId());
+ System.out.println("consoleHandle = " + params.getConsoleHandle());
+
+ // Sleep a while, getting query result as they become available
+ try
+ {
+ Thread.sleep(20000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+
+ // Refresh the subscription getting results asynchronously, just for variety
+ System.out.println("Calling refreshSubscription on " + params.getSubscriptionId());
+ _console.refreshSubscription(params.getSubscriptionId(), "{replyHandle:ignored}");
+
+
+ // Sleep a bit more
+ try
+ {
+ Thread.sleep(350000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + ": AgentSubscriptionTestConsole failed");
+ System.exit(1);
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ System.out.println("WorkItem type: " + wi.getType());
+
+ if (wi.getType() == AGENT_HEARTBEAT)
+ {
+ AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+ Agent agent = item.getAgent();
+ System.out.println(agent.getName());
+ }
+
+ if (wi.getType() == EVENT_RECEIVED)
+ {
+ EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+ Agent agent = item.getAgent();
+ QmfEvent event = item.getEvent();
+
+ String className = event.getSchemaClassId().getClassName();
+ System.out.println("Event: " + className);
+//event.listValues();
+ }
+
+ if (wi.getType() == METHOD_RESPONSE)
+ {
+ MethodResponseWorkItem item = (MethodResponseWorkItem)wi;
+ MethodResult result = item.getMethodResult();
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ System.out.println(result.getStringValue("message"));
+ }
+
+ if (wi.getType() == OBJECT_UPDATE)
+ {
+ ObjectUpdateWorkItem item = (ObjectUpdateWorkItem)wi;
+ QmfConsoleData object = item.getQmfConsoleData();
+ ObjectId objectId = object.getObjectId();
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ System.out.println("objectId = " + objectId);
+ System.out.println("MethodCount = " + object.getLongValue("methodCount"));
+ }
+
+ if (wi.getType() == SUBSCRIBE_RESPONSE)
+ {
+ SubscribeResponseWorkItem item = (SubscribeResponseWorkItem)wi;
+ SubscribeParams params = item.getSubscribeParams();
+ System.out.println("duration = " + params.getLifetime());
+ System.out.println("interval = " + params.getPublishInterval());
+ System.out.println("subscriptionId = " + params.getSubscriptionId());
+ System.out.println("consoleHandle = " + params.getConsoleHandle());
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ }
+
+ if (wi.getType() == SUBSCRIPTION_INDICATION)
+ {
+ SubscriptionIndicationWorkItem item = (SubscriptionIndicationWorkItem)wi;
+ SubscribeIndication indication = item.getSubscribeIndication();
+ String correlationId = indication.getConsoleHandle();
+ System.out.println("correlationId = " + correlationId);
+
+ List<QmfConsoleData> objects = indication.getData();
+ for (QmfConsoleData object : objects)
+ {
+ if (object.isDeleted())
+ {
+ System.out.println("object has been deleted");
+ }
+ System.out.println("offset = " + object.getValue("offset"));
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ AgentSubscriptionTestConsole test = new AgentSubscriptionTestConsole(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("AgentSubscriptionTestConsole main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending AgentSubscriptionTestConsole ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java
new file mode 100644
index 0000000000..8aebe76937
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTest.java
@@ -0,0 +1,298 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.Agent;
+import org.apache.qpid.qmf2.agent.MethodCallParams;
+import org.apache.qpid.qmf2.agent.MethodCallWorkItem;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * A class used to test the Agent API functionality.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentTest implements QmfEventListener
+{
+ private Agent _agent;
+ private QmfAgentData _control;
+ private SchemaObjectClass _exceptionSchema;
+ private SchemaObjectClass _controlSchema;
+ private SchemaObjectClass _childSchema;
+ private SchemaEventClass _eventSchema;
+
+ public AgentTest(String url)
+ {
+ try
+ {
+ System.out.println("** Starting AgentTest a test of basic Agent class functions **");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _agent = new Agent(this);
+ _agent.setVendor("profitron.com");
+ _agent.setProduct("gizmo");
+ _agent.setValue("attr1", 2000);
+
+ System.out.println("Agent name: " + _agent.getName());
+
+ setupSchema();
+ populateData();
+
+ _agent.setConnection(connection);
+
+ for (int i = 0; i < 100; i++)
+ {
+ _control.setValue("offset", i);
+ //control.update(); // Send data indication to the Subscriber on the next Subscription interval
+ _control.publish(); // Send data indication to the Subscriber immediately
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+
+ _control.destroy();
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentTest failed");
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ System.out.println("WorkItem type: " + wi.getType());
+ _control.incValue("methodCount", 1);
+
+ if (wi.getType() == METHOD_CALL)
+ {
+ MethodCallWorkItem item = (MethodCallWorkItem)wi;
+ MethodCallParams methodCallParams = item.getMethodCallParams();
+ String methodName = methodCallParams.getName();
+ ObjectId objectId = methodCallParams.getObjectId();
+ String userId = methodCallParams.getUserId();
+ userId = userId.equals("") ? "anonymous" : userId;
+ QmfData inArgs = methodCallParams.getArgs();
+ ObjectId controlAddress = _control.getObjectId();
+
+ System.out.println("Method Call User ID = " + userId);
+
+ try
+ {
+ if (objectId == null)
+ {
+ // Method invoked directly on Agent
+ if (methodName.equals("toString"))
+ {
+ QmfData outArgs = new QmfData();
+ outArgs.setValue("string", _agent.toString());
+ _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+ }
+ }
+ else if (objectId.equals(controlAddress))
+ {
+ if (methodName.equals("stop"))
+ {
+ System.out.println("Invoked stop method");
+ String message = inArgs.getStringValue("message");
+ System.out.println("Stopping: message = " + message);
+ _agent.methodResponse(methodName, item.getHandle(), null, null);
+ _agent.destroy();
+ System.exit(1);
+ }
+ else if (methodName.equals("echo"))
+ {
+ System.out.println("Invoked echo method");
+ _agent.methodResponse(methodName, item.getHandle(), inArgs, null);
+ }
+ else if (methodName.equals("event"))
+ {
+ System.out.println("Invoked event method");
+ QmfEvent event = new QmfEvent(_eventSchema);
+ event.setSeverity((int)inArgs.getLongValue("severity"));
+ event.setValue("text", inArgs.getStringValue("text"));
+ _agent.raiseEvent(event);
+ _agent.methodResponse(methodName, item.getHandle(), null, null);
+ }
+ else if (methodName.equals("fail"))
+ {
+ System.out.println("Invoked fail method");
+ QmfData error = new QmfData();
+ if (inArgs.getBooleanValue("useString"))
+ {
+ error.setValue("error_text", inArgs.getStringValue("stringVal"));
+ }
+ else
+ {
+ error.setValue("whatHappened", "It Failed");
+ error.setValue("howBad", 75);
+ error.setValue("details", inArgs.getValue("details"));
+ }
+ _agent.methodResponse(methodName, item.getHandle(), null, error);
+ }
+ else if (methodName.equals("create_child"))
+ {
+ System.out.println("Invoked create_child method");
+ String childName = inArgs.getStringValue("name");
+ System.out.println("childName = " + childName);
+ QmfAgentData child = new QmfAgentData(_childSchema);
+ child.setValue("name", childName);
+ _agent.addObject(child);
+ QmfData outArgs = new QmfData();
+ outArgs.setRefValue("childAddr", child.getObjectId(), "reference"); // Set subtype just to test
+ _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+ }
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: AgentTest failed");
+ QmfData error = new QmfData();
+ error.setValue("error_text", qmfe.getMessage());
+ _agent.methodResponse(methodName, item.getHandle(), null, error);
+ }
+ }
+ }
+
+ public void setupSchema() throws QmfException
+ {
+ System.out.println("*** AgentTest initialising the various Schema classes ***");
+
+ // Create and register schema for this agent.
+ String packageName = "com.profitron.gizmo";
+
+ // Declare a schema for a structured exception that can be used in failed method invocations.
+ _exceptionSchema = new SchemaObjectClass(packageName, "exception");
+ _exceptionSchema.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+ _exceptionSchema.addProperty(new SchemaProperty("howBad", QmfType.TYPE_INT));
+ _exceptionSchema.addProperty(new SchemaProperty("details", QmfType.TYPE_MAP));
+
+ // Declare a control object to test methods against.
+ _controlSchema = new SchemaObjectClass(packageName, "control");
+ _controlSchema.addProperty(new SchemaProperty("state", QmfType.TYPE_STRING));
+ _controlSchema.addProperty(new SchemaProperty("methodCount", QmfType.TYPE_INT));
+ _controlSchema.addProperty(new SchemaProperty("offset", QmfType.TYPE_INT));
+ _controlSchema.setIdNames("state");
+
+ SchemaMethod stopMethod = new SchemaMethod("stop", "Stop Agent");
+ stopMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:IN}"));
+ _controlSchema.addMethod(stopMethod);
+
+ SchemaMethod echoMethod = new SchemaMethod("echo", "Echo Arguments");
+ echoMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING, "{dir:INOUT}"));
+ _controlSchema.addMethod(echoMethod);
+
+ SchemaMethod eventMethod = new SchemaMethod("event", "Raise an Event");
+ eventMethod.addArgument(new SchemaProperty("text", QmfType.TYPE_STRING, "{dir:IN}"));
+ eventMethod.addArgument(new SchemaProperty("severity", QmfType.TYPE_INT, "{dir:IN}"));
+ _controlSchema.addMethod(eventMethod);
+
+ SchemaMethod failMethod = new SchemaMethod("fail", "Expected to Fail");
+ failMethod.addArgument(new SchemaProperty("useString", QmfType.TYPE_BOOL, "{dir:IN}"));
+ failMethod.addArgument(new SchemaProperty("stringVal", QmfType.TYPE_STRING, "{dir:IN}"));
+ failMethod.addArgument(new SchemaProperty("details", QmfType.TYPE_MAP, "{dir:IN}"));
+ _controlSchema.addMethod(failMethod);
+
+ SchemaMethod createMethod = new SchemaMethod("create_child", "Create Child Object");
+ createMethod.addArgument(new SchemaProperty("name", QmfType.TYPE_STRING, "{dir:IN}"));
+ createMethod.addArgument(new SchemaProperty("childAddr", QmfType.TYPE_MAP, "{dir:OUT}"));
+ _controlSchema.addMethod(createMethod);
+
+ // Declare the child class
+ _childSchema = new SchemaObjectClass(packageName, "child");
+ _childSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+ _childSchema.setIdNames("name");
+
+ // Declare the event class
+ _eventSchema = new SchemaEventClass(packageName, "event");
+ _eventSchema.addProperty(new SchemaProperty("text", QmfType.TYPE_STRING));
+
+ System.out.println("AgentTest Schema classes initialised OK");
+
+ _agent.registerObjectClass(_exceptionSchema);
+ _agent.registerObjectClass(_controlSchema);
+ _agent.registerObjectClass(_childSchema);
+ _agent.registerEventClass(_eventSchema);
+
+ System.out.println("AgentTest Schema classes registered OK");
+ }
+
+ public void populateData() throws QmfException
+ {
+ System.out.println("*** AgentTest creating a control object ***");
+
+ _control = new QmfAgentData(_controlSchema);
+ _control.setValue("state", "OPERATIONAL");
+ _control.setValue("methodCount", 0);
+ _agent.addObject(_control);
+ System.out.println("AgentTest Schema control object added OK");
+ }
+
+
+ public static void main(String[] args)
+ {
+ //System.out.println("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ AgentTest test1 = new AgentTest(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("ConnectionAudit main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending AgentTest ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java
new file mode 100644
index 0000000000..edae41bcf4
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/AgentTestConsole.java
@@ -0,0 +1,308 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.MethodResponseWorkItem;
+import org.apache.qpid.qmf2.console.ObjectUpdateWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * This class is the Console part of AgentTest which together provide a test of a number of core Console and
+ * Agent behaviours such as Schema creation, registration and lookup, Object lookup, method invocation on Objects
+ * Object refreshing (updating state of local proxy objects from the real Agent).
+ *
+ * N.B. AgentTest needs to be running for this test to behave as expected.
+ *
+ * @author Fraser Adams
+ */
+public final class AgentTestConsole implements QmfEventListener
+{
+ private Console _console;
+ private Agent _gizmo;
+
+ public AgentTestConsole(String url)
+ {
+ try
+ {
+ System.out.println("*** Starting AgentTestConsole used to test basic Console and Agent behaviour ***");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(this);
+ _console.addConnection(connection);
+
+ // Wait until the gizmo Agent has been discovered
+ synchronized(this)
+ {
+ while (_gizmo == null)
+ {
+ long startTime = System.currentTimeMillis();
+ try
+ {
+ wait(10*1000);
+ }
+ catch (InterruptedException ie)
+ {
+ continue;
+ }
+ // Measure elapsed time to test against spurious wakeups and ensure we really have timed out
+ long elapsedTime = (System.currentTimeMillis() - startTime)/1000;
+ if (_gizmo == null && elapsedTime >= 10)
+ {
+ System.out.println("gizmo Agent not found, you probably need to run AgentTest");
+ System.exit(1);
+ }
+ }
+ }
+
+ System.out.println("Testing lookup of control objects by name");
+ List<QmfConsoleData> controls = _console.getObjects("com.profitron.gizmo", "control");
+ if (controls.size() > 0)
+ {
+ System.out.println("control object found");
+ QmfConsoleData control = controls.get(0);
+ //control.listValues();
+
+ ObjectId oid = control.getObjectId();
+ //System.out.println("Agent Name = " + oid.getAgentName());
+ //System.out.println("Agent Epoch = " + oid.getAgentEpoch());
+ //System.out.println("Object Name = " + oid.getObjectName());
+
+ System.out.println("Testing lookup of object by ObjectId");
+ controls = _console.getObjects(oid);
+
+ if (controls.size() == 0)
+ {
+ System.out.println("No objects returned from ObjectId lookup: AgentTestConsole failed");
+ System.exit(1);
+ }
+
+ System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+ QmfData inArgs;
+ QmfData outArgs;
+ MethodResult results;
+
+/*
+ System.out.println("Testing invokeMethod(toString, args) - method called directly on Agent");
+ results = _gizmo.invokeMethod("toString", null);
+ System.out.println("gizmo.toString() = " + results.getArguments().getStringValue("string"));
+*/
+
+ // ********** Invoke create_child nethod **********
+ System.out.println("Testing invokeMethod(create_child, args)");
+ inArgs = new QmfData();
+ inArgs.setValue("name", "child 1");
+
+ results = control.invokeMethod("create_child", inArgs);
+ if (!results.succeeded())
+ {
+ System.out.println("create_child returned an exception object");
+ System.exit(1);
+ }
+
+ if (!results.hasValue("childAddr"))
+ {
+ System.out.println("create_child returned an unexpected value");
+ System.exit(1);
+ }
+
+ ObjectId childId = results.getRefValue("childAddr");
+ System.out.println("childId = " + childId);
+ System.out.println("childAddr subtype = " + results.getSubtype("childAddr"));
+ QmfConsoleData child1 = _console.getObjects(childId).get(0);
+ System.out.println("child1 name = " + child1.getStringValue("name"));
+
+
+ // Update and display state of control object
+ control.refresh();
+ System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+
+
+ // ********** Invoke event nethod **********
+ System.out.println("Testing invokeMethod(event, args) ");
+ inArgs = new QmfData();
+ inArgs.setValue("text", "Attention Will Robinson!! Aliens have just invaded");
+ inArgs.setValue("severity", 0);
+ control.invokeMethod("event", inArgs);
+
+
+ // Update and display state of control object
+ control.refresh();
+ System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+
+
+ // ********** Invoke fail nethod **********
+ System.out.println("Testing invokeMethod(fail, args) ");
+ QmfData details = new QmfData();
+ details.setValue("detail1", "something bad");
+ details.setValue("detail2", "something even badder");
+ inArgs = new QmfData();
+ inArgs.setValue("details", details.mapEncode());
+ results = control.invokeMethod("fail", inArgs);
+ System.out.println("whatHappened: " + results.getStringValue("whatHappened"));
+ System.out.println("howBad: " + results.getLongValue("howBad"));
+
+ // Update and display state of control object
+ control.refresh();
+ System.out.println("MethodCount = " + control.getLongValue("methodCount"));
+
+
+ // ********** Invoke echo nethod asynchronously **********
+ System.out.println("Testing asynchronous call of invokeMethod(echo, args) ");
+ inArgs = new QmfData();
+ inArgs.setValue("message", "This message should be echoed by the Agent");
+ control.invokeMethod("echo", inArgs, "echoMethodCorrelationId");
+
+
+ // Asynchronous update and display state of control object. The state here should be the same as
+ // the last time it was called as this is an asynchronous refresh. The ObjectUpdateWorkItem in
+ // the event handler contains the new state
+ control.refresh("echoMethodCorrelationId");
+ System.out.println("MethodCount = " + control.getLongValue("methodCount") + " (should be same as last value)");
+
+
+
+ // ********** Invoke stop nethod, this will stop the Agent **********
+ System.out.println("Testing invokeMethod(stop, args) ");
+ inArgs = new QmfData();
+ inArgs.setValue("message", "Ladies and gentlemen Elvis has just left the building");
+ control.invokeMethod("stop", inArgs);
+
+
+ }
+ else
+ {
+ System.out.println("No control objects returned: AgentTestConsole failed");
+ System.exit(1);
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + ": AgentTestConsole failed");
+ System.exit(1);
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ System.out.println("WorkItem type: " + wi.getType());
+
+ if (wi.getType() == AGENT_ADDED)
+ {
+ AgentAddedWorkItem item = (AgentAddedWorkItem)wi;
+ Agent agent = item.getAgent();
+
+ // If this is the gizmo Agent we notify the main thread so processing can continue.
+ if (agent.getProduct().equals("gizmo"))
+ {
+ synchronized(this)
+ {
+ _gizmo = agent;
+ notify();
+ }
+ }
+ }
+
+ if (wi.getType() == AGENT_HEARTBEAT)
+ {
+ AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+ Agent agent = item.getAgent();
+ System.out.println(agent.getName());
+ }
+
+ if (wi.getType() == EVENT_RECEIVED)
+ {
+ EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+ Agent agent = item.getAgent();
+ QmfEvent event = item.getEvent();
+
+ String className = event.getSchemaClassId().getClassName();
+ System.out.println("Event: " + className);
+//event.listValues();
+ }
+
+ if (wi.getType() == METHOD_RESPONSE)
+ {
+ MethodResponseWorkItem item = (MethodResponseWorkItem)wi;
+ MethodResult result = item.getMethodResult();
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ System.out.println(result.getStringValue("message"));
+ }
+
+ if (wi.getType() == OBJECT_UPDATE)
+ {
+ ObjectUpdateWorkItem item = (ObjectUpdateWorkItem)wi;
+ QmfConsoleData object = item.getQmfConsoleData();
+ ObjectId objectId = object.getObjectId();
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ System.out.println("objectId = " + objectId);
+ System.out.println("MethodCount = " + object.getLongValue("methodCount"));
+ }
+
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ AgentTestConsole test = new AgentTestConsole(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("AgentTestConsole main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending AgentTestConsole ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java
new file mode 100644
index 0000000000..a6613464b5
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTest.java
@@ -0,0 +1,174 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.agent.Agent;
+import org.apache.qpid.qmf2.agent.MethodCallParams;
+import org.apache.qpid.qmf2.agent.MethodCallWorkItem;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * A class used to test the Agent API functionality. This Agent specifies an explicit queue name and a larger than
+ * default queue size so that it can receive large payloads on its methods.
+ *
+ * @author Fraser Adams
+ */
+public final class BigPayloadAgentTest implements QmfEventListener
+{
+ private Agent _agent;
+ private QmfAgentData _control;
+ private SchemaObjectClass _controlSchema;
+
+ public BigPayloadAgentTest(String url)
+ {
+ try
+ {
+ System.out.println("** Starting BigPayloadAgentTest a test of basic Agent class functions **");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _agent = new Agent(this);
+ _agent.setVendor("test.com");
+ _agent.setProduct("big-payload-agent");
+
+ System.out.println("Agent name: " + _agent.getName());
+
+ setupSchema();
+ populateData();
+ _agent.setConnection(connection, " ; {link: {name:'big-payload-agent', x-declare: {arguments: {'qpid.policy_type': ring, 'qpid.max_size': 500000000}}}}");
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: BigPayloadAgentTest failed");
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ System.out.println("WorkItem type: " + wi.getType());
+
+ if (wi.getType() == METHOD_CALL)
+ {
+ MethodCallWorkItem item = (MethodCallWorkItem)wi;
+ MethodCallParams methodCallParams = item.getMethodCallParams();
+ String methodName = methodCallParams.getName();
+ ObjectId objectId = methodCallParams.getObjectId();
+
+ QmfData inArgs = methodCallParams.getArgs();
+ ObjectId controlAddress = _control.getObjectId();
+
+ if (objectId.equals(controlAddress))
+ {
+ if (methodName.equals("processPayload"))
+ {
+ System.out.println("Invoked processPayload method");
+
+ byte[] parameter = inArgs.getValue("parameter");
+ System.out.println("payload size = " + parameter.length);
+
+ QmfData outArgs = new QmfData();
+ outArgs.setValue("return", parameter);
+ _agent.methodResponse(methodName, item.getHandle(), outArgs, null);
+ }
+ }
+ }
+ }
+
+ public void setupSchema() throws QmfException
+ {
+ System.out.println("*** BigPayloadAgentTest initialising the various Schema classes ***");
+
+ // Create and register schema for this agent.
+ String packageName = "com.test.bigagent";
+
+ // Declare a control object to test methods against.
+ _controlSchema = new SchemaObjectClass(packageName, "control");
+ _controlSchema.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+ _controlSchema.setIdNames("name");
+
+ SchemaMethod createMethod = new SchemaMethod("processPayload", "Process a large payload");
+ createMethod.addArgument(new SchemaProperty("parameter", QmfType.TYPE_STRING, "{dir:IN}"));
+ createMethod.addArgument(new SchemaProperty("return", QmfType.TYPE_STRING, "{dir:OUT}"));
+ _controlSchema.addMethod(createMethod);
+
+ System.out.println("BigPayloadAgentTest Schema classes initialised OK");
+
+ _agent.registerObjectClass(_controlSchema);
+
+ System.out.println("BigPayloadAgentTest Schema classes registered OK");
+ }
+
+ public void populateData() throws QmfException
+ {
+ System.out.println("*** BigPayloadAgentTest creating a control object ***");
+
+ _control = new QmfAgentData(_controlSchema);
+ _control.setValue("name", "controller");
+ _agent.addObject(_control);
+ System.out.println("BigPayloadAgentTest Schema control object added OK");
+ }
+
+
+ public static void main(String[] args)
+ {
+ //System.out.println("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ BigPayloadAgentTest test1 = new BigPayloadAgentTest(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("ConnectionAudit main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending BigPayloadAgentTest ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java
new file mode 100644
index 0000000000..4457dea5e5
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BigPayloadAgentTestConsole.java
@@ -0,0 +1,155 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.MethodResponseWorkItem;
+import org.apache.qpid.qmf2.console.ObjectUpdateWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * This class is the Console part of AgentTest which together provide a test of a number of core Console and
+ * Agent behaviours such as Schema creation, registration and lookup, Object lookup, method invocation on Objects
+ * Object refreshing (updating state of local proxy objects from the real Agent).
+ *
+ * N.B. AgentTest needs to be running for this test to behave as expected.
+ *
+ * @author Fraser Adams
+ */
+public final class BigPayloadAgentTestConsole implements QmfEventListener
+{
+ private Console _console;
+ private Agent _agent;
+
+ public BigPayloadAgentTestConsole(String url)
+ {
+ try
+ {
+ System.out.println("*** Starting BigPayloadAgentTestConsole used to test basic Console and Agent behaviour ***");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(this);
+ _console.addConnection(connection, " ; {link: {name:'big-payload-console', x-declare: {arguments: {'qpid.policy_type': ring, 'qpid.max_size': 500000000}}}}");
+
+ // Wait until the broker Agent has been discovered
+ _agent = _console.findAgent("big-payload-agent");
+ if (_agent == null)
+ {
+ System.out.println("Big Payload Agent not found");
+ System.exit(1);
+ }
+
+ List<QmfConsoleData> controls = _console.getObjects("com.test.bigagent", "control");
+ if (controls.size() > 0)
+ {
+ QmfConsoleData control = controls.get(0);
+
+ // ********** Invoke processPayload nethod **********
+ System.out.println("Testing invokeMethod(processPayload, args)");
+ QmfData inArgs = new QmfData();
+ inArgs.setValue("parameter", new byte[150000000]);
+
+ MethodResult results = control.invokeMethod("processPayload", inArgs);
+ if (!results.succeeded())
+ {
+ System.out.println("processPayload returned an exception object");
+ System.exit(1);
+ }
+
+ if (!results.hasValue("return"))
+ {
+ System.out.println("processPayload returned an unexpected value");
+ System.exit(1);
+ }
+
+ byte[] returnVal = results.getValue("return");
+ System.out.println("returnVal size = " + returnVal.length);
+ }
+ else
+ {
+ System.out.println("No control objects returned: BigPayloadAgentTestConsole failed");
+ System.exit(1);
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + ": BigPayloadAgentTestConsole failed");
+ System.exit(1);
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ //System.out.println("WorkItem type: " + wi.getType());
+
+ if (wi.getType() == AGENT_HEARTBEAT)
+ {
+ AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+ Agent agent = item.getAgent();
+ System.out.println(agent.getName());
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ BigPayloadAgentTestConsole test = new BigPayloadAgentTestConsole(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("BigPayloadAgentTestConsole main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending BigPayloadAgentTestConsole ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BrokerSubscriptionTestConsole.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BrokerSubscriptionTestConsole.java
new file mode 100644
index 0000000000..27eadbaac8
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/BrokerSubscriptionTestConsole.java
@@ -0,0 +1,262 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.EventReceivedWorkItem;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.MethodResponseWorkItem;
+import org.apache.qpid.qmf2.console.ObjectUpdateWorkItem;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.console.SubscribeIndication;
+import org.apache.qpid.qmf2.console.SubscribeParams;
+import org.apache.qpid.qmf2.console.SubscribeResponseWorkItem;
+import org.apache.qpid.qmf2.console.SubscriptionIndicationWorkItem;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * This class provides a test of broker subscription behaviour.
+ * <p>
+ * N.B. That the 0.12 C++ broker does not *actually* support subscriptions however it does periodically "push"
+ * QmfConsoleData Object updates as _data indications. The Console class uses these to provide client side
+ * emulation of broker subscriptions. One slightly subtle thing to bear in mind however is that the broker
+ * ManagementAgent separates "properties" and "statistics" so for example a subscription query on say a queue's
+ * name property will only evaluate true for a properties push and not a statistics push. The most useful usage
+ * pattern is likely to be a getObjects() call to return all queues, followed by a search for the queue of interest
+ * then a subscription with a query using the ObjectId of the wanted queue.
+ *
+ * @author Fraser Adams
+ */
+public final class BrokerSubscriptionTestConsole implements QmfEventListener
+{
+ private Console _console;
+ private Agent _broker;
+ private ObjectId _objectId; // Used to test ObjectId Query
+
+ public BrokerSubscriptionTestConsole(String url)
+ {
+ try
+ {
+ System.out.println("** Starting BrokerSubscriptionTestConsole used to test subscription behaviour **");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(this);
+ _console.addConnection(connection);
+
+ // Wait until the broker Agent has been discovered
+ _broker = _console.findAgent("broker");
+ if (_broker == null)
+ {
+ System.out.println("broker Agent not found");
+ System.exit(1);
+ }
+
+ System.out.println("Creating Query for objects whose name property has a value that starts with 'a'");
+
+ SubscribeParams params;
+ QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, "['re_match', 'name', ['quote', '^a']]");
+
+ // Create a subscription, response returned synchronously
+ params = _console.createSubscription(_broker, query, "consoleHandle1", "{publishInterval:5}");
+ System.out.println("duration = " + params.getLifetime());
+ System.out.println("interval = " + params.getPublishInterval());
+ System.out.println("subscriptionId = " + params.getSubscriptionId());
+ System.out.println("consoleHandle = " + params.getConsoleHandle());
+
+ // Sleep a while, getting query result as they become available
+ try
+ {
+ Thread.sleep(20000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+
+ // Refresh the subscription getting results asynchronously, just for variety
+ System.out.println("Calling refreshSubscription on " + params.getSubscriptionId());
+ _console.refreshSubscription(params.getSubscriptionId(), "{replyHandle:ignoredReplyHandle}");
+
+
+ // Create a subscription for _class_name = queue
+ System.out.println("Creating Query for all queue objects");
+ query = new QmfQuery(QmfQueryTarget.OBJECT, "['eq', '_class_name', ['quote', 'queue']]");
+ params = _console.createSubscription(_broker, query, "queues");
+
+ while (_objectId == null)
+ {
+ System.out.println("Waiting for ObjectId to be set");
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+
+ // Cancel the query for all queue objects
+ System.out.println("Cancelling Query for all queue objects");
+ _console.cancelSubscription(params.getSubscriptionId());
+
+ // Create a subscription for _object_id
+ System.out.println("Creating Query for _object_id = " + _objectId);
+ query = new QmfQuery(QmfQueryTarget.OBJECT, _objectId);
+ params = _console.createSubscription(_broker, query, "queues");
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + ": BrokerSubscriptionTestConsole failed");
+ System.exit(1);
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ System.out.println("WorkItem type: " + wi.getType());
+
+ if (wi.getType() == AGENT_HEARTBEAT)
+ {
+ AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi;
+ Agent agent = item.getAgent();
+ System.out.println(agent.getName());
+ }
+
+ if (wi.getType() == EVENT_RECEIVED)
+ {
+ EventReceivedWorkItem item = (EventReceivedWorkItem)wi;
+ Agent agent = item.getAgent();
+ QmfEvent event = item.getEvent();
+
+ String className = event.getSchemaClassId().getClassName();
+ System.out.println("Event: " + className);
+//event.listValues();
+ }
+
+ if (wi.getType() == METHOD_RESPONSE)
+ {
+ MethodResponseWorkItem item = (MethodResponseWorkItem)wi;
+ MethodResult result = item.getMethodResult();
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ System.out.println(result.getStringValue("message"));
+ }
+
+ if (wi.getType() == OBJECT_UPDATE)
+ {
+ ObjectUpdateWorkItem item = (ObjectUpdateWorkItem)wi;
+ QmfConsoleData object = item.getQmfConsoleData();
+ ObjectId objectId = object.getObjectId();
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ System.out.println("objectId = " + objectId);
+ System.out.println("MethodCount = " + object.getLongValue("methodCount"));
+ }
+
+ if (wi.getType() == SUBSCRIBE_RESPONSE)
+ {
+ SubscribeResponseWorkItem item = (SubscribeResponseWorkItem)wi;
+ SubscribeParams params = item.getSubscribeParams();
+ System.out.println("duration = " + params.getLifetime());
+ System.out.println("interval = " + params.getPublishInterval());
+ System.out.println("subscriptionId = " + params.getSubscriptionId());
+ System.out.println("consoleHandle = " + params.getConsoleHandle());
+ String correlationId = item.getHandle().getCorrelationId();
+ System.out.println("correlationId = " + correlationId);
+ }
+
+ if (wi.getType() == SUBSCRIPTION_INDICATION)
+ {
+ SubscriptionIndicationWorkItem item = (SubscriptionIndicationWorkItem)wi;
+ SubscribeIndication indication = item.getSubscribeIndication();
+ String correlationId = indication.getConsoleHandle();
+ System.out.println("correlationId = " + correlationId);
+
+ List<QmfConsoleData> objects = indication.getData();
+ for (QmfConsoleData object : objects)
+ {
+ if (object.isDeleted())
+ {
+ System.out.println("object has been deleted");
+ }
+ String className = object.getSchemaClassId().getClassName();
+ System.out.println("object class = " + className);
+ if (className.equals("queue") || className.equals("exchange"))
+ {
+ if (object.hasValue("name"))
+ {
+ System.out.println("property update, name = " + object.getStringValue("name"));
+ }
+ else
+ {
+ _objectId = object.getObjectId();
+ System.out.println("statistic update, oid = " + _objectId);
+ }
+ }
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ BrokerSubscriptionTestConsole test = new BrokerSubscriptionTestConsole(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ // Blocks here until return is pressed
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("BrokerSubscriptionTestConsole main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending BrokerSubscriptionTestConsole ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/InvokeMethodTest.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/InvokeMethodTest.java
new file mode 100644
index 0000000000..8b175e3ca6
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/InvokeMethodTest.java
@@ -0,0 +1,112 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.SchemaClass;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.MethodResult;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+
+/**
+ * This class tests invoking a method lots of times.
+ *
+ * @author Fraser Adams
+ */
+public final class InvokeMethodTest implements QmfEventListener
+{
+ private Console _console;
+
+ public InvokeMethodTest(String url)
+ {
+ try
+ {
+ System.out.println("*** Starting InvokeMethodTest ctrl^C to exit ***");
+ System.out.println("This is intended to soak test QMF2 invokeMethod, it doesn't do anything obvious");
+ System.out.println("but attaching jconsole shows memory consumption. It *looks* like it's leaking");
+ System.out.println("memory, but it turns out to be due to the use of a SoftReference in Qpid's");
+ System.out.println("setReplyTo() method on JMSMessage. Consumption *eventually* flattens out...");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(this);
+ _console.addConnection(connection);
+
+ // First we create a large number of queues using the QMF2 create method on the broker object
+ List<QmfConsoleData> brokers = _console.getObjects("org.apache.qpid.broker", "broker");
+ if (brokers.isEmpty())
+ {
+ System.out.println("No broker QmfConsoleData returned");
+ System.exit(1);
+ }
+
+ QmfConsoleData broker = brokers.get(0);
+ QmfData arguments = new QmfData();
+
+ while (true)
+ {
+ try
+ {
+ MethodResult results = broker.invokeMethod("getLogLevel", arguments);
+//System.out.println(results.getStringValue("level"));
+ }
+ catch (QmfException e)
+ { // This may be throw if we've already added the queues, we just catch and ignore for this test.
+ //System.out.println(e.getMessage());
+ }
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + ": InvokeMethodTest failed");
+ System.exit(1);
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ }
+
+ public static void main(String[] args)
+ {
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ InvokeMethodTest test = new InvokeMethodTest(url);
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/PartialGetObjectsTest.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/PartialGetObjectsTest.java
new file mode 100644
index 0000000000..e42879947b
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/PartialGetObjectsTest.java
@@ -0,0 +1,177 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.SchemaClass;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+
+/**
+ * This class tests the case where getObjects() returns "a lot" of objects. The broker ManagementAgent actually
+ * sends multiple messages in this case with the initial messages marked with a "partial" header. The Console
+ * getObjects() method needs to be able to support receiving multiple response messages when the "partial"
+ * header is set.
+ *
+ * @author Fraser Adams
+ */
+public final class PartialGetObjectsTest implements QmfEventListener
+{
+ private Console _console;
+
+ public PartialGetObjectsTest(String url)
+ {
+ try
+ {
+ System.out.println("*** Starting PartialGetObjectsTest used to test schema retrieval ***");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(this);
+ _console.addConnection(connection);
+
+ // First we create a large number of queues using the QMF2 create method on the broker object
+ List<QmfConsoleData> brokers = _console.getObjects("org.apache.qpid.broker", "broker");
+ if (brokers.isEmpty())
+ {
+ System.out.println("No broker QmfConsoleData returned");
+ System.exit(1);
+ }
+
+ QmfConsoleData broker = brokers.get(0);
+ QmfData arguments = new QmfData();
+ arguments.setValue("type", "queue");
+
+ for (int i = 0; i < 300; i++)
+ {
+ arguments.setValue("name", "test " + i);
+
+ try
+ {
+ broker.invokeMethod("create", arguments);
+ }
+ catch (QmfException e)
+ { // This may be throw if we've already added the queues, we just catch and ignore for this test.
+ //System.out.println(e.getMessage());
+ }
+ }
+
+ // After we've created lots of queues we attempt to list them. This list should include all the queues
+ // we've added irrespective of the number.
+ List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
+ System.out.println("Call 1 Returned " + queues.size() + " objects");
+ for (QmfConsoleData queue : queues)
+ {
+ String name = queue.getStringValue("name");
+ System.out.println("Queue: " + name);
+ }
+
+ // We get the queue objects a second time. If getObjects() correctly handles partial responses then
+ // this should return the complete list of queue objects, if not it will only return the subset that
+ // corresponds to the additional partial responses. Not handling these messages is likely to be a very
+ // bad thing as subsequent QMF requests will then start to receive the wrong responses.
+ queues = _console.getObjects("org.apache.qpid.broker", "queue");
+ System.out.println("Call 2 Returned " + queues.size() + " objects");
+ for (QmfConsoleData queue : queues)
+ {
+ String name = queue.getStringValue("name");
+ System.out.println("Queue: " + name);
+ }
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + ": PartialGetObjectsTest failed");
+ System.exit(1);
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ /* if (wi instanceof AgentAddedWorkItem)
+ {
+ AgentAddedWorkItem item = (AgentAddedWorkItem)wi;
+ Agent agent = item.getAgent();
+ System.out.println("\nAgent " + agent.getName() + " added ");
+
+ // Retrieve the List of SchemaClassIds from the Agent, these will be used to retrieve the Schema.
+ List<SchemaClassId> schemaClassIds = _console.getClasses(agent);
+
+ if (schemaClassIds.size() > 0)
+ {
+ // For each retrieved Class retrieve and display the Schema.
+ for (SchemaClassId schemaClassId : schemaClassIds)
+ {
+ List<SchemaClass> schema = _console.getSchema(schemaClassId, agent);
+ if (schema.size() == 1)
+ {
+ schema.get(0).listValues();
+ }
+ }
+ }
+ else
+ {
+ System.out.println("No schema information is available for this Agent");
+ }
+ }*/
+
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ PartialGetObjectsTest test = new PartialGetObjectsTest(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("PartialGetObjectsTest main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending PartialGetObjectsTest ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/SchemaTest.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/SchemaTest.java
new file mode 100644
index 0000000000..f510bb201c
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/SchemaTest.java
@@ -0,0 +1,126 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfData;
+import org.apache.qpid.qmf2.common.QmfEvent;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.SchemaClass;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.AgentAddedWorkItem;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+
+/**
+ * This class retrieves schema information when it detects that Agents have been added.
+ *
+ * @author Fraser Adams
+ */
+public final class SchemaTest implements QmfEventListener
+{
+ private Console _console;
+
+ public SchemaTest(String url)
+ {
+ try
+ {
+ System.out.println("*** Starting SchemaTest used to test schema retrieval ***");
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(this);
+ _console.addConnection(connection);
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + ": SchemaTest failed");
+ System.exit(1);
+ }
+ }
+
+ public void onEvent(WorkItem wi)
+ {
+ if (wi instanceof AgentAddedWorkItem)
+ {
+ AgentAddedWorkItem item = (AgentAddedWorkItem)wi;
+ Agent agent = item.getAgent();
+ System.out.println("\nAgent " + agent.getName() + " added ");
+
+ // Retrieve the List of SchemaClassIds from the Agent, these will be used to retrieve the Schema.
+ List<SchemaClassId> schemaClassIds = _console.getClasses(agent);
+
+ if (schemaClassIds.size() > 0)
+ {
+ // For each retrieved Class retrieve and display the Schema.
+ for (SchemaClassId schemaClassId : schemaClassIds)
+ {
+ List<SchemaClass> schema = _console.getSchema(schemaClassId, agent);
+ if (schema.size() == 1)
+ {
+ schema.get(0).listValues();
+ }
+ }
+ }
+ else
+ {
+ System.out.println("No schema information is available for this Agent");
+ }
+ }
+
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ SchemaTest test = new SchemaTest(url);
+
+ BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
+ try
+ { // Blocks here until return is pressed
+ System.out.println("Hit Return to exit");
+ String s = commandLine.readLine();
+ System.exit(0);
+ }
+ catch (IOException e)
+ {
+ System.out.println ("SchemaTest main(): IOException: " + e.getMessage());
+ }
+
+ System.out.println("*** Ending SchemaTest ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test1.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test1.java
new file mode 100644
index 0000000000..f71f4cdf32
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test1.java
@@ -0,0 +1,140 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.BlockingNotifier;
+import org.apache.qpid.qmf2.common.Notifier;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+
+/**
+ * A class used to test the basic Console Agent discovery behaviour
+ *
+ * @author Fraser Adams
+ */
+
+public final class Test1
+{
+ private Console _console;
+
+ public Test1(String url)
+ {
+ try
+ {
+ System.out.println("*** Starting Test1 synchronous Agent discovery ***");
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console();
+ _console.addConnection(connection);
+
+ System.out.println("*** Test1 testing _console.getAgents(): ***");
+ List<Agent> agents = _console.getAgents();
+
+ if (agents.size() == 0)
+ {
+ System.out.println("*** Test1 failed, _console.getAgents() should return at least Broker Agent ***");
+ System.exit(1);
+ }
+
+ for (Agent agent : agents)
+ {
+ agent.listValues();
+ }
+
+ System.out.println("*** Test1 testing _console.getAgent(\"broker\"): ***");
+ Agent agent = _console.getAgent("broker");
+ agent.listValues();
+
+ System.out.println("*** Test1 testing _console.findAgent(\"broker\"): ***");
+ agent = _console.findAgent("broker");
+ if (agent == null)
+ {
+ System.out.println("*** Test1 _console.findAgent(\"broker\") returned null : Test1 failed ***");
+ System.exit(1);
+ }
+ else
+ {
+ agent.listValues();
+ }
+
+
+ System.out.println("*** Test1 testing _console.findAgent(\"monkey\"): ***");
+ agent = _console.findAgent("monkey");
+ if (agent == null)
+ {
+ System.out.println("*** Test1 _console.findAgent(\"monkey\") correctly returned null ***");
+ }
+ else
+ {
+ agent.listValues();
+ }
+
+
+ System.out.println("*** Test1 testing _console.getObjects(\"broker\"): ***");
+ List<QmfConsoleData> brokers = _console.getObjects("broker");
+ if (brokers.size() == 0)
+ {
+ System.out.println("*** Test1 _console.getObjects(\"broker\") should return at least one object : Test1 failed ***");
+ System.exit(1);
+ }
+ else
+ {
+ for (QmfConsoleData broker : brokers)
+ {
+ broker.listValues();
+ }
+ }
+
+ System.out.println("*** Ending Test1 ***");
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: Test1 failed");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ // As of Qpid 0.16 the Session Dispatcher Thread is non-Daemon so the JVM gets prevented from exiting.
+ // Setting the following property to true makes it a Daemon Thread.
+ System.setProperty("qpid.jms.daemon.dispatcher", "true");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ Test1 test1 = new Test1(url);
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test2.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test2.java
new file mode 100644
index 0000000000..11924f824d
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test2.java
@@ -0,0 +1,121 @@
+/*
+ *
+ * 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.qmf2.test;
+
+import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.BlockingNotifier;
+import org.apache.qpid.qmf2.common.Notifier;
+import org.apache.qpid.qmf2.common.QmfEventListener;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.WorkItem;
+import org.apache.qpid.qmf2.console.Agent;
+import org.apache.qpid.qmf2.console.Console;
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*;
+
+/**
+ * A class used to test a non-blocking query for all Agents using the Notifier/WorkItem Event API. As most of
+ * the tests and samples use the alternative QmfEventListener API (because the author prefers that) rather than
+ * the official QMF2 WorkQueue API it seems sensible to include at least one test illustrating that.
+ *
+ * Note that in practice the WorkQueue API can also be used without an explicit notifier as one of the
+ * overloaded Console getNextWorkitem() methods is a blocking call to the WorkQueue that blocks until a WorkItem
+ * is available. The approach used in this class is for API illustration purposes and the author is unlikely to
+ * use it for anything useful.
+ *
+ * @author Fraser Adams
+ */
+
+public final class Test2
+{
+ private Console _console;
+
+ public Test2(String url)
+ {
+ try
+ {
+ System.out.println("*** Starting Test2 asynchronous Agent discovery using WorkQueue API ***");
+
+ BlockingNotifier notifier = new BlockingNotifier();
+
+ Connection connection = ConnectionHelper.createConnection(url, "{reconnect: true}");
+ _console = new Console(notifier);
+//console.disableAgentDiscovery(); // To miss all notifications this needs done before addConnection()
+ _console.addConnection(connection);
+
+ int count = 0;
+ while (true)
+ {
+ notifier.waitForWorkItem();
+ System.out.println("WorkItem available, WorkItem count = " + _console.getWorkitemCount());
+
+ WorkItem wi;
+ while ((wi = _console.getNextWorkitem(0)) != null)
+ {
+ System.out.println("WorkItem type: " + wi.getType());
+ if (wi.getType() == AGENT_HEARTBEAT || wi.getType() == AGENT_ADDED ||
+ wi.getType() == AGENT_DELETED || wi.getType() == AGENT_RESTARTED ||
+ wi.getType() == EVENT_RECEIVED)
+ {
+ Map<String, Object> p = wi.<Map<String, Object>>getParams();
+ Agent agent = (Agent)p.get("agent");
+ System.out.println(agent.getName());
+ }
+ }
+
+ count++;
+ if (count == 10)
+ {
+ System.out.println("Applying Agent Discovery Query ['eq', '_product', ['quote', 'gizmo']]");
+ System.out.println("This should disable broker Agent events but allow gizmo Agent events");
+ System.out.println("Run AgentTest to prove this");
+ QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, "['eq', '_product', ['quote', 'gizmo']]");
+ _console.enableAgentDiscovery(query);
+ }
+ }
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: Test2 failed");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ String url = (args.length == 1) ? args[0] : "localhost";
+ Test2 test2 = new Test2(url);
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test3.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test3.java
new file mode 100644
index 0000000000..fdb9180d36
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test3.java
@@ -0,0 +1,137 @@
+/*
+ *
+ * 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.qmf2.test;
+
+// Misc Imports
+import java.io.*;
+import java.util.List;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+
+/**
+ * A class used to test the Schema classes
+ *
+ * @author Fraser Adams
+ */
+public final class Test3
+{
+ public Test3()
+ {
+ try
+ {
+ System.out.println("*** Starting Test3 testing the various Schema classes ***");
+
+ // Create and register schema for this agent.
+ String packageName = "com.profitron.gizmo";
+
+ // Declare a schema for a structured exception that can be used in failed method invocations.
+ SchemaObjectClass exception = new SchemaObjectClass(packageName, "exception");
+
+ exception.addProperty(new SchemaProperty("whatHappened", QmfType.TYPE_STRING));
+ exception.addProperty(new SchemaProperty("howBad", QmfType.TYPE_INT));
+ exception.addProperty(new SchemaProperty("details", QmfType.TYPE_MAP));
+
+ // Declare a control object to test methods against.
+ SchemaObjectClass control = new SchemaObjectClass(packageName, "control");
+ control.addProperty(new SchemaProperty("state", QmfType.TYPE_STRING));
+ control.addProperty(new SchemaProperty("methodCount", QmfType.TYPE_INT));
+
+ SchemaMethod stopMethod = new SchemaMethod("stop", "Stop Agent");
+ stopMethod.addArgument(new SchemaProperty("message", QmfType.TYPE_STRING));
+ control.addMethod(stopMethod);
+
+ SchemaMethod echoMethod = new SchemaMethod("echo", "Echo Arguments");
+ echoMethod.addArgument(new SchemaProperty("sequence", QmfType.TYPE_INT, "{dir:INOUT}"));
+ echoMethod.addArgument(new SchemaProperty("map", QmfType.TYPE_MAP, "{dir:INOUT}"));
+ control.addMethod(echoMethod);
+
+ SchemaMethod eventMethod = new SchemaMethod("event", "Raise an Event");
+ eventMethod.addArgument(new SchemaProperty("text", QmfType.TYPE_STRING, "{dir:IN}"));
+ eventMethod.addArgument(new SchemaProperty("severity", QmfType.TYPE_INT, "{dir:IN}"));
+ control.addMethod(eventMethod);
+
+ SchemaMethod failMethod = new SchemaMethod("fail", "Expected to Fail");
+ failMethod.addArgument(new SchemaProperty("useString", QmfType.TYPE_BOOL, "{dir:IN}"));
+ failMethod.addArgument(new SchemaProperty("stringVal", QmfType.TYPE_STRING, "{dir:IN}"));
+ failMethod.addArgument(new SchemaProperty("details", QmfType.TYPE_MAP, "{dir:IN}"));
+ control.addMethod(failMethod);
+
+ SchemaMethod createMethod = new SchemaMethod("create_child", "Create Child Object");
+ createMethod.addArgument(new SchemaProperty("name", QmfType.TYPE_STRING, "{dir:IN}"));
+ createMethod.addArgument(new SchemaProperty("childAddr", QmfType.TYPE_MAP, "{dir:OUT}"));
+ control.addMethod(createMethod);
+
+ // Declare the child class
+ SchemaObjectClass child = new SchemaObjectClass(packageName, "child");
+ child.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+
+ // Declare the event class
+ SchemaEventClass event = new SchemaEventClass(packageName, "event");
+ event.addProperty(new SchemaProperty("text", QmfType.TYPE_STRING));
+
+ System.out.println("Test3 Schema classes initialised OK");
+
+ // Now we create new instance of each class from the map encodings and list the values
+ // to check everything looks OK.
+
+ System.out.println("Test3 testing serialisation of exception schema");
+ SchemaObjectClass exceptionFromMap = new SchemaObjectClass(exception.mapEncode());
+ exceptionFromMap.listValues();
+ System.out.println();
+
+ System.out.println("Test3 testing serialisation of control schema");
+ SchemaObjectClass controlFromMap = new SchemaObjectClass(control.mapEncode());
+ controlFromMap.listValues();
+ System.out.println();
+
+ System.out.println("Test3 testing serialisation of child schema");
+ SchemaObjectClass childFromMap = new SchemaObjectClass(child.mapEncode());
+ childFromMap.listValues();
+ System.out.println();
+
+ System.out.println("Test3 testing serialisation of event schema");
+ SchemaEventClass eventFromMap = new SchemaEventClass(event.mapEncode());
+ eventFromMap.listValues();
+ System.out.println();
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: Test3 failed");
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ Test3 Test3 = new Test3();
+
+ System.out.println("*** Ending Test3 ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test4.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test4.java
new file mode 100644
index 0000000000..29a8ba8f88
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/Test4.java
@@ -0,0 +1,339 @@
+/*
+ *
+ * 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.qmf2.test;
+
+// Misc Imports
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.common.ObjectId;
+import org.apache.qpid.qmf2.common.QmfException;
+import org.apache.qpid.qmf2.common.QmfQuery;
+import org.apache.qpid.qmf2.common.QmfQueryTarget;
+import org.apache.qpid.qmf2.common.QmfType;
+import org.apache.qpid.qmf2.common.SchemaClass;
+import org.apache.qpid.qmf2.common.SchemaClassId;
+import org.apache.qpid.qmf2.common.SchemaEventClass;
+import org.apache.qpid.qmf2.common.SchemaMethod;
+import org.apache.qpid.qmf2.common.SchemaObjectClass;
+import org.apache.qpid.qmf2.common.SchemaProperty;
+
+import org.apache.qpid.qmf2.console.QmfConsoleData;
+import org.apache.qpid.qmf2.agent.QmfAgentData;
+
+
+/**
+ * A class used to test the QmfQuery classes
+ *
+ * @author Fraser Adams
+ */
+public final class Test4
+{
+
+ private Map<SchemaClassId, SchemaClass> _schemaCache = new ConcurrentHashMap<SchemaClassId, SchemaClass>();
+ private Map<ObjectId, QmfAgentData> _objectIndex = new ConcurrentHashMap<ObjectId, QmfAgentData>();
+
+ public Test4()
+ {
+ try
+ {
+ System.out.println("*** Starting Test4 testing the QmfQuery class ***");
+
+ // Create and register schema for this agent.
+ String packageName = "com.fadams.qmf2";
+
+ // Declare a mammal class to test against.
+ SchemaObjectClass mammal = new SchemaObjectClass(packageName, "mammal");
+ mammal.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+ mammal.addProperty(new SchemaProperty("legs", QmfType.TYPE_INT));
+ mammal.setIdNames("name");
+
+ // Declare an insect class to test against.
+ SchemaObjectClass insect = new SchemaObjectClass(packageName, "insect");
+ insect.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+ insect.addProperty(new SchemaProperty("legs", QmfType.TYPE_INT));
+ insect.setIdNames("name");
+
+ // Declare a reptile class to test against.
+ SchemaObjectClass reptile = new SchemaObjectClass(packageName, "reptile");
+ reptile.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+ reptile.addProperty(new SchemaProperty("legs", QmfType.TYPE_INT));
+ reptile.setIdNames("name");
+
+ // Declare a bird class to test against.
+ SchemaObjectClass bird = new SchemaObjectClass(packageName, "bird");
+ bird.addProperty(new SchemaProperty("name", QmfType.TYPE_STRING));
+ bird.addProperty(new SchemaProperty("legs", QmfType.TYPE_INT));
+ bird.setIdNames("name");
+
+
+ registerObjectClass(mammal);
+ registerObjectClass(insect);
+ registerObjectClass(reptile);
+ registerObjectClass(bird);
+
+ QmfAgentData cat = new QmfAgentData(mammal);
+ cat.setValue("name", "cat");
+ cat.setValue("legs", 4l);
+ addObject(cat);
+
+ QmfAgentData dog = new QmfAgentData(mammal);
+ dog.setValue("name", "dog");
+ dog.setValue("legs", 4l);
+ addObject(dog);
+
+ QmfAgentData rabbit = new QmfAgentData(mammal);
+ rabbit.setValue("name", "rabbit");
+ rabbit.setValue("legs", 4);
+ addObject(rabbit);
+
+ QmfAgentData horse = new QmfAgentData(mammal);
+ horse.setValue("name", "horse");
+ horse.setValue("legs", 4);
+ addObject(horse);
+
+ QmfAgentData human = new QmfAgentData(mammal);
+ human.setValue("name", "human");
+ human.setValue("legs", 2);
+ addObject(human);
+
+
+ QmfAgentData wasp = new QmfAgentData(insect);
+ wasp.setValue("name", "wasp");
+ wasp.setValue("legs", 6);
+ addObject(wasp);
+
+ QmfAgentData ant = new QmfAgentData(insect);
+ ant.setValue("name", "ant");
+ ant.setValue("legs", 6);
+ addObject(ant);
+
+ QmfAgentData crocodile = new QmfAgentData(reptile);
+ crocodile.setValue("name", "crocodile");
+ crocodile.setValue("legs", 4);
+ addObject(crocodile);
+
+ QmfAgentData gecko = new QmfAgentData(reptile);
+ gecko.setValue("name", "gecko");
+ gecko.setValue("legs", 4);
+ addObject(gecko);
+
+ QmfAgentData python = new QmfAgentData(reptile);
+ python.setValue("name", "python");
+ python.setValue("legs", 0);
+ addObject(python);
+
+ QmfAgentData hawk = new QmfAgentData(bird);
+ hawk.setValue("name", "hawk");
+ hawk.setValue("legs", 2);
+ addObject(hawk);
+
+ QmfAgentData ostrich = new QmfAgentData(bird);
+ ostrich.setValue("name", "ostrich");
+ ostrich.setValue("legs", 2);
+ addObject(ostrich);
+
+
+ System.out.println("total number of objects registered: " + _objectIndex.size());
+
+ QmfQuery query;
+ List<QmfConsoleData> results;
+
+ System.out.println("looking up wasp object by ID");
+ query = new QmfQuery(QmfQueryTarget.OBJECT, wasp.getObjectId());
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+ System.out.println("\nlooking up mammal objects");
+ query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("mammal"));
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+ System.out.println("\nlooking up everything in package com.fadams.qmf2");
+ query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("com.fadams.qmf2", null));
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+
+ System.out.println("\nQuery for all mammals with more than two legs");
+ String predicate = "['and', ['eq', '_package_name', ['quote', 'com.fadams.qmf2']], " +
+ "['eq', '_class_name', ['quote', 'mammal']], " +
+ "['gt', 'legs', 2]]";
+
+ //predicate = "['eq', '_package_name', ['quote', 'com.fadams.qmf2']]";
+
+ //predicate = "[]";
+
+ query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
+ System.out.println(query.getPredicate());
+
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+
+ System.out.println("\nQuery for everything with less than four legs");
+ predicate = "['lt', 'legs', 4]";
+
+ query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
+ System.out.println(query.getPredicate());
+
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+
+ System.out.println("\nQuery for everything with between two and four legs");
+ predicate = "['and', ['ge', 'legs', 2], " +
+ "['le', 'legs', 4]]";
+
+ query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
+ System.out.println(query.getPredicate());
+
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+
+ System.out.println("\nQuery for all reptiles or birds");
+ predicate = "['or', ['eq', '_class_name', ['quote', 'reptile']], " +
+ "['eq', '_class_name', ['quote', 'bird']]]";
+
+ query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
+ System.out.println(query.getPredicate());
+
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+
+ System.out.println("\nQuery for everything whose name matches the regex ^h");
+ predicate = "['re_match', 'name', ['quote', '^h']]";
+
+ query = new QmfQuery(QmfQueryTarget.OBJECT, predicate);
+ System.out.println(query.getPredicate());
+
+ results = evaluateDataQuery(query);
+ displayResults(results);
+
+
+ }
+ catch (QmfException qmfe)
+ {
+ System.err.println("QmfException " + qmfe.getMessage() + " caught: Test4 failed");
+ }
+ }
+
+ public void registerObjectClass(SchemaObjectClass schema)
+ {
+ SchemaClassId classId = schema.getClassId();
+ _schemaCache.put(classId, schema);
+ }
+
+ public void addObject(QmfAgentData object) throws QmfException
+ {
+ SchemaClassId classId = object.getSchemaClassId();
+ SchemaClass schema = _schemaCache.get(classId);
+
+ // Try to create an objectName using the set of property names that have been specified as idNames in the schema
+ StringBuilder buf = new StringBuilder();
+ if (schema != null && schema instanceof SchemaObjectClass)
+ {
+ String[] idNames = ((SchemaObjectClass)schema).getIdNames();
+ for (String name : idNames)
+ {
+ buf.append(object.getStringValue(name));
+ }
+ }
+ String objectName = buf.toString();
+
+ // If the schema hasn't given any help we use a UUID
+ if (objectName.length() == 0) objectName = UUID.randomUUID().toString();
+
+ // Finish up the name by incorporating package and class names
+ objectName = classId.getPackageName() + ":" + classId.getClassName() + ":" + objectName;
+
+ // Now we've got a good name for the object we create it's ObjectId and add that to the object
+ ObjectId addr = new ObjectId("test"/*name*/, objectName, 0/*epoch*/);
+ object.setObjectId(addr);
+
+ if (_objectIndex.get(addr) != null)
+ {
+ throw new QmfException("Duplicate QmfAgentData Address");
+ }
+
+ _objectIndex.put(addr, object);
+ }
+
+
+ public List<QmfConsoleData> evaluateDataQuery(QmfQuery query)
+ {
+ List<QmfConsoleData> results = new ArrayList<QmfConsoleData>();
+
+ if (query.getObjectId() != null)
+ {
+ // Look up a QmfAgentData object by the ObjectId obtained from the query
+ ObjectId objectId = query.getObjectId();
+ QmfAgentData object = _objectIndex.get(objectId);
+ if (object != null && !object.isDeleted())
+ {
+ results.add(new QmfConsoleData(object.mapEncode(), null));
+ }
+ }
+ else
+ {
+ for (QmfAgentData object : _objectIndex.values())
+ {
+ if (!object.isDeleted() && query.evaluate(object))
+ {
+ results.add(new QmfConsoleData(object.mapEncode(), null));
+ }
+ }
+ }
+
+ return results;
+ }
+
+ public List<SchemaClass> evaluateSchemaQuery(QmfQuery query)
+ {
+ return null;
+ }
+
+
+ public void displayResults(List<QmfConsoleData> values)
+ {
+ for (QmfConsoleData object : values)
+ {
+ System.out.println("name = " + object.getStringValue("name") + ", legs = " + object.getLongValue("legs"));
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ Test4 Test4 = new Test4();
+
+ System.out.println("*** Ending Test4 ***");
+ }
+}
diff --git a/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/URLTest.java b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/URLTest.java
new file mode 100644
index 0000000000..35bd9f537b
--- /dev/null
+++ b/qpid/tools/src/java/src/test/java/org/apache/qpid/qmf2/test/URLTest.java
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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.qmf2.test;
+
+//import javax.jms.Connection;
+
+// Misc Imports
+import java.io.*;
+
+// QMF2 Imports
+import org.apache.qpid.qmf2.util.ConnectionHelper;
+
+/**
+ * A class used to test the ConnectionHelper utility, which provides support for a range of AMQP URL formats
+ * and a basic wrapper for Connection creation.
+ *
+ * @author Fraser Adams
+ */
+
+public final class URLTest
+{
+ public static void main(String[] args)
+ {
+ //System.out.println ("Setting log level to FATAL");
+ System.setProperty("amqj.logging.level", "FATAL");
+
+ System.out.println("Running URLTest, this tests ConnectionHelper.createConnectionURL() for various URL formats.");
+ System.out.println("It doesn't actually create a connection, it just displays the resulting ConnectionURL");
+
+ String url;
+ url = ConnectionHelper.createConnectionURL("localhost");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("localhost:5672", "{username: foo, password: bar, reconnect: true, reconnect_timeout: 5, reconnect_limit: 5000, tcp-nodelay: true, heartbeat: 10, protocol: ssl}");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("guest/guest@localhost:5672", "{reconnect: true, tcp-nodelay: true}");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp:localhost:5672, tcp:localhost:5673", "{reconnect: true, tcp-nodelay: true, failover: roundrobin, cyclecount: 20}");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp://foo:bar@host1:1234/vhost?clientid=baz");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp://localhost");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp://vm:foo:1234,tcp:foo:5678/");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp://host1,host2,host3/?retry=2");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp://host1,host2?retry=2,host3");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp://grok:hostname?flavour=strawberry;frobnication=on/vhost");
+ System.out.println(url);
+
+ url = ConnectionHelper.createConnectionURL("amqp://host?ssl=true");
+ System.out.println(url);
+ }
+}
diff --git a/qpid/tools/src/java/test/bin/AgentExternalTest.sh b/qpid/tools/src/java/test/bin/AgentExternalTest.sh
new file mode 100755
index 0000000000..566e291b91
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/AgentExternalTest.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.AgentExternalTest "$@"
diff --git a/qpid/tools/src/java/test/bin/AgentSubscriptionTestConsole.sh b/qpid/tools/src/java/test/bin/AgentSubscriptionTestConsole.sh
new file mode 100755
index 0000000000..eedeb6a9ea
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/AgentSubscriptionTestConsole.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.AgentSubscriptionTestConsole "$@"
diff --git a/qpid/tools/src/java/test/bin/AgentTest.sh b/qpid/tools/src/java/test/bin/AgentTest.sh
new file mode 100755
index 0000000000..7418caa534
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/AgentTest.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.AgentTest "$@"
diff --git a/qpid/tools/src/java/test/bin/AgentTestConsole.sh b/qpid/tools/src/java/test/bin/AgentTestConsole.sh
new file mode 100755
index 0000000000..ecd6f9ebf1
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/AgentTestConsole.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.AgentTestConsole "$@"
diff --git a/qpid/tools/src/java/test/bin/BigPayloadAgentTest.sh b/qpid/tools/src/java/test/bin/BigPayloadAgentTest.sh
new file mode 100755
index 0000000000..049416678c
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/BigPayloadAgentTest.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.BigPayloadAgentTest "$@"
diff --git a/qpid/tools/src/java/test/bin/BigPayloadAgentTestConsole.sh b/qpid/tools/src/java/test/bin/BigPayloadAgentTestConsole.sh
new file mode 100755
index 0000000000..bdf2b9d517
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/BigPayloadAgentTestConsole.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.BigPayloadAgentTestConsole "$@"
diff --git a/qpid/tools/src/java/test/bin/BrokerSubscriptionTestConsole.sh b/qpid/tools/src/java/test/bin/BrokerSubscriptionTestConsole.sh
new file mode 100755
index 0000000000..6fd2aae0e8
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/BrokerSubscriptionTestConsole.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.BrokerSubscriptionTestConsole "$@"
diff --git a/qpid/tools/src/java/test/bin/InvokeMethodTest.sh b/qpid/tools/src/java/test/bin/InvokeMethodTest.sh
new file mode 100755
index 0000000000..7f4cc82362
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/InvokeMethodTest.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.InvokeMethodTest "$@"
diff --git a/qpid/tools/src/java/test/bin/PartialGetObjectsTest.sh b/qpid/tools/src/java/test/bin/PartialGetObjectsTest.sh
new file mode 100755
index 0000000000..cdc76bcd8d
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/PartialGetObjectsTest.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.PartialGetObjectsTest "$@"
diff --git a/qpid/tools/src/java/test/bin/SchemaTest.sh b/qpid/tools/src/java/test/bin/SchemaTest.sh
new file mode 100755
index 0000000000..6e24896d2c
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/SchemaTest.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.SchemaTest "$@"
diff --git a/qpid/tools/src/java/test/bin/Test1.sh b/qpid/tools/src/java/test/bin/Test1.sh
new file mode 100755
index 0000000000..d48cf2e501
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/Test1.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.Test1 "$@"
diff --git a/qpid/tools/src/java/test/bin/Test2.sh b/qpid/tools/src/java/test/bin/Test2.sh
new file mode 100755
index 0000000000..be2d903a8f
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/Test2.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.Test2 "$@"
diff --git a/qpid/tools/src/java/test/bin/Test3.sh b/qpid/tools/src/java/test/bin/Test3.sh
new file mode 100755
index 0000000000..e5af741b47
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/Test3.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.Test3
diff --git a/qpid/tools/src/java/test/bin/Test4.sh b/qpid/tools/src/java/test/bin/Test4.sh
new file mode 100755
index 0000000000..97025bfedf
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/Test4.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.Test4
diff --git a/qpid/tools/src/java/test/bin/URLTest.sh b/qpid/tools/src/java/test/bin/URLTest.sh
new file mode 100755
index 0000000000..10dde796b7
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/URLTest.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# 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.
+#
+
+WHEREAMI=`dirname $0`
+if [ -z "$QMF2_HOME" ]; then
+ export QMF2_HOME=`cd $WHEREAMI/../../ && pwd`
+fi
+
+QMF2_LIBS=$QMF2_HOME/build/lib
+
+CLASSPATH=$QMF2_LIBS/qpid-client-patch.jar:$CLASSPATH:$QMF2_LIBS/qmf2.jar:$QMF2_LIBS/qmf2test.jar
+
+java -cp $CLASSPATH org.apache.qpid.qmf2.test.URLTest
diff --git a/qpid/tools/src/java/test/bin/log4j.xml b/qpid/tools/src/java/test/bin/log4j.xml
new file mode 100644
index 0000000000..d5169932bc
--- /dev/null
+++ b/qpid/tools/src/java/test/bin/log4j.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <param name="Threshold" value="ALL"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%m%n"/>
+ </layout>
+ </appender>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+ <root>
+ <priority value="INFO" />
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>